Solvedpm2 pm2 start npm -- start error

Your issue may already be reported!
Please search on the issue tracker before creating one.

What's going wrong?

After I run pm2 start npm -- start,then get errored.
error info is

(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.

SyntaxError: Unexpected token :
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Object.<anonymous> (C:\Users\marek\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:83:21)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.

I found someone get the same error in stackoverflow.
Maybe it only get errored in win10, It works in my macbook.

How could we reproduce this issue?

2.npm install
3.npm run build
4.pm2 start npm -- start

Supporting information

--- PM2 REPORT (Fri May 11 2018 11:01:16 GMT+0800 (中国标准时间)) -------------------

--- Daemon -------------------------------------------------
pm2d version : 2.10.3
node version : 8.11.1
node path : undefined
argv : C:\Program Files\nodejs\node.exe,C:\Users\marek\AppData\Roaming\npm\node_modules\pm2\lib\Daemon.js
argv0 : node
user : undefined
uid : N/A
gid : N/A
uptime : 58min

--- CLI ----------------------------------------------------
local pm2 : 2.10.3
node version : 8.11.1
node path : undefined
argv : C:\Program Files\nodejs\node.exe,C:\Users\marek\AppData\Roaming\npm\node_modules\pm2\bin\pm2,report
argv0 : node
user : chenpei

--- System info --------------------------------------------
arch : x64
platform : win32
type : Windows_NT
cpus : Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
cpus nb : 8
freemem : 8662110208
totalmem : 17035272192
home : C:\Users\marek

--- PM2 list -----------------------------------------------
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
│ pm-web │ 0 │ fork │ 0 │ errored │ 15 │ 0 │ 0% │ 0 B │ chenpei │ disabled │

--- Daemon logs --------------------------------------------
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
│ pm-web │ 0 │ fork │ 0 │ errored │ 15 │ 0 │ 0% │ 0 B │ chenpei │ disabled │

28 Answers

✔️Accepted Answer

This is still happening on my Windows 10 machine. Whatever globally installed program from npm I try to start from pm2, it gives me this error.

Seems like pm2 assumes the program passed (npm, verdaccio, or whatever) to be a js file to be run with node, when they actually are .cmd files.
Reason I think so : you get the exact same errors if you locate the <app>.cmd file and try to run
node <path_to_app>/<app>.cmd. Of course node doesn't like to have to run a .cmd file.

I wonder however why pm2 makes that assumption. Because if you try pm2 start node for example, that works fine. It seems to only make the assumption on programs installed from npm (but I haven't tested a ton either).

However that all means there is a relatively easy workaround if you need it for now. As pm2 assumes a js file, just pass to pm2 the .js file that the .cmd is trying to run. Locate the .js that the .cmd is trying to run, and give the absolute path to pm2. For instance:
pm2 start "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js"
pm2 start C:\Users\Nicolas\AppData\Roaming\npm\node_modules\...\<script>.js

That also works if you put it in the ecosystem file, as the script entry for the app.

Other Answers:

I mean just closing an issue does not make it disappear. @Unitech Please consider to accept PR #4887 - I mean if the community tries to help, at least there should be a reaction. Thx to @myso-kr

I am also unable to find the solution.Getting below error :

SyntaxError: Unexpected token ':'
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Object. (C:\Users\suresh-negi\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:32:23)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)


@nguiard Thanks for your workaround, works as expected. Only thing is I get a cmd window open whenever I run the command. Any idea how to prevent this?

Related Issues:

pm2 How do I call `pm2` to check if a process with given name is running?
For me the problem was that any of the above solutions I tried gave a non-zero exit code which would...
pm2 How do you run a TypeScript app with ts-node parameters?
I am using pm2 start ts-node -- -P tsconfig.server.json ./server/index.ts I normally run my app with...
pm2 Latest and pm2 causing issues when using -i max
I know this one is old and closed When I launch my app.js file via pm2 start app.js -i max I get the...
pm2 Systemctl error: PID file not readable (yet)
I have this issue on Arch Linux with Node.js v9.6.1 and pm2 2.10.1 It is strange that it DOES create...
pm2 pm2 start npm -- start error
This is still happening on my Windows 10 machine Whatever globally installed program from npm I try ...
pm2 Can't supply command line arguments to script
A standard unix way of doing such things would be something like that: pm2 start script.js -- -d 1 w...
pm2 pm2 for java - Shell script launching java process, stop doesn't stop the java process
Here you go Can we use pm2 for java? If yes can you provide a working example? ...
pm2 Startup is not starting pm2 daemon and saved process
I had this issue too wanting to run pm2 as root i installed pm2 as global package on ubuntu (aws ins...
pm2 Spawning PM2 daemon with pm2_home=/home/tealou/.pm2
I got the same problem i had fixed it.. It's because of the version conflict Now i use node version ...
pm2 Multiple instance of an app (in fork mode) bound to different ports + load balancing using nginx
I was able to launch multiple instances of the same script using json config: pm2.json: ...
pm2 pm2 cluster mode fails to start because `Error: ENOENT, no such file or directory` for process.cwd()
pm2 update solves. same as #1244 This always happen when stop the old server replace the source code...
pm2 Too Many Unstable Restarts
Are you using nvm or n to install pm2? I think it's due to a bad node version from the modules Pleas...
pm2 Install hangs behind corporate firewall on
OK so my issue was basically #2700 npm install --g --no-optional pm2 worked. Hello ...
pm2 Pass instance id to app as environment variable
Hi process.env.pm_id does that :) When starting pm2 with multiple instances for a specific app ...
pm2 pm2 deploy doesn't read neither ~/.profile nor ~/.bashrc
Might be your .bashrc file contains lines like these # If not running interactively ...
pm2 PM2 Start failing when using .JSON
TLDR Useful information for pm2-docker users googling this cryptic message (as I have been doing on ...
pm2 Interpreter ts-node doest not seem to be available when using package.json script
I was facing exact same error Problem was confusion between global pm2 with local pm2 installed in n...
pm2 Error message "[PM2][ERROR] Interpreter none does not seems to be available"
Same result and there is no exec_interpreter option in processes.json If reporting a bug please use ...
pm2 How to start a script in python's module type with pipenv?
Writing here for other people who want to know how to write the above command: into an ecosystem fil...
terminal Typing inside of the default WSL terminal feels amazing, why is it better than every other app?
I really do not mind when someone comes by and decides to tell us that we're doing a good job at som...
ripgrep Add support for replace in files
This is more easily accomplished using sed than I think people realize sed is quite a beast and is n...
terminal Guide for build and installation
This information should be included in the Building the Code section of the README file. ...
terminal error 0x80070002 when launching `powershell.exe'
Just add the path of the power shell to the environment variable Thank you It works! %systemroot%\Sy...
gitsome Command "python egg_info" failed with error code 1 in /tmp/pip-build-7SrToZ/gitsome/
I had the same problem on OSX and Solve my issue (I have both python versions installed). ...
bat Ubuntu install error when rg is installed also
As a workaround one can use sudo apt install -o Dpkg::Options::=--force-overwrite bat ripgrep (taken...
terminal Move the solution to VS2019 and v142 toolset
As mentioned in README (also related to #534) If you're running VS2019 ...
terminal MEGATHREAD: Breaking settings changes in version 0.11!
Out of curiosity BREAKING SETTINGS CHANGES IN 0.11 BREAKING CHANGE We've deleted a lot of legacy set...
ConEmu Arrow keys not working in Bash for Windows
@ErrantErinaceinae Are you kidding? Months??? The issue was created four days ago! This is absolutel...
terminal Windows Terminal keeps forgetting/can't find my default WSL Ubuntu profile
Happened to me (seemingly) after updating Docker for Windows Haven't had any issues with WSL2 for mo...
ripgrep hidden files to be searched by default
The following is @okdana's solution but with the .git folder remaining ignored: ...
ConEmu Windows Subsystem For Linux Bash Specify Startup Directory
@NitroBAY Ops I made a mistake The Windows file system is mounted to Windows Subsystem For Linux(WSL...
terminal Terminal hangs on exit with 'process exited with code 127' message
@carragom Oh that explains it - closeOnExit is a Profile setting Hi! I've noticed that on newer rele...
bat [fzf] Bat is awesome, but
It's so awesome but whyyyyy Whenever bat detects a non-interactive terminal it will fall back to pri...
PowerShell Equivalent of bash set -e
$erroractionpreference = stop only works if Write-Error is called (such as an exception is raised) I...
terminal Alt arrow keys do nothing; key unbinding broken?
This behavior is due to #3585 Proper expected behavior is restored with the following: ...
ripgrep ripgrep no way to exclude directory e.g. Tests and search for all *.c files
@sumonto you're correct $ rg -w str1 -tc -g '!tests/*' would do what you want So is that not working...
ConEmu WSL2 no longer working after windows update
Thank you This does indeed work You don't need to specify the user (the default one that corresponds...
exa Static binary downloaded from release not working, lacking libhttp_parser
A sudo apt install libhttp-parser2.1 fixed it for me on ubuntu17 but I don't see why this tool would...
http server it does not work when i reload the browser after navigating to a route.
@thornjad Great it works with SPA: http-server --gzip --proxy http://localhost:8080? ...
ripgrep Option for outputting absolute paths
I don't see how that's a niche problem judging from others mentioning here they have the with the sa...
PowerShell pwsh as a dotnet global tool exhibits very unusual behavior with Ctrl-C
Unless Scoop is using the dotnet global tool wrapper shipped with PowerShell this is likely an issue...
winget cli winget should install an app if there is an exact match (eg 'git')
Fall into the pit of success Search = case insensitive non-exact match Install = case insensitive ex...
http server The header content contains invalid characters?
\http-server\node_modules\ecstatic\lib\ecstatic\etag.js I install the package and write a simple htm...
micro copy paste doesn't work well
Thanks @SrMordred this fixed this issue for me too! Hello I like where micro is going It's truly the...
winget cli Permission Denied when running from bash
FYI a easy workaround is to add e.g to your .bashrc and alias using winpty (included by default in m...
terminal Vim Cursor shape stays underscore. Not able to change it
@tuyenpm9 that's no $PS1 that's a %PROMPT% setting in CMD:
ConEmu Active tab is hard to see
So here's a more concrete proposal: have tab templates support a new %* token for the Selected tab w...
terminal It is hard to find Microsoft.VCLibs.140.00.UWPDesktop
@atom0s Thanks for the info The seemed a bit shady to me but I can confirm that...
terminal Azure Cloud Shell is readded to the profiles.json file after I remove it and restart terminal.
@Alacritous thanks for not including those invectives Steps to reproduce Open profiles.json through ...
terminal Large number of "'function' is not a member of 'std'" errors
If you're trying to build on VS19 add #include <functional> below #include <filesystem> in LibraryIn...