'Node JS PM2 SyntaxError: Unexpected token import

I have a node application that runs on Docker and Kubernetes is used for managing the pods. When I deploy a new version, it will restart and create a new pod. Now I have added some logger messages to my application and deployed them and when I list the pods, it is showing that status as CrashLoopBackOff for my application. Now when I checked the logs for that particular pod as shown below, it is saying there is an error with PM2 and it shows as follows:

server01:my-user-name ~ $  kubectl logs -f my-app-6876fc9c4c-tbfd8 -n name-space --tail 2000

2022-03-16T13:00:23: PM2 log: Launching in no daemon mode
2022-03-16T13:00:23: PM2 log: App [www:0] starting in -fork mode-
2022-03-16T13:00:23: PM2 log: App [www:0] online
/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:30
    import(url.pathToFileURL(process.env.pm_exec_path));
    ^^^^^^
SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
2022-03-16T13:00:24: PM2 log: App [www:0] exited with code [1] via signal [SIGINT]
2022-03-16T13:00:24: PM2 log: App [www:0] starting in -fork mode-
2022-03-16T13:00:24: PM2 log: App [www:0] online
/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:30
    import(url.pathToFileURL(process.env.pm_exec_path));
    ^^^^^^

Now I removed my logger messages and deployed them again, but the error still persists. How can I fix this ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source