Pm2: `pm2 start npm -- start` error

Created on 11 May 2018  Β·  20Comments  Β·  Source: Unitech/pm2

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

C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(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)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(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?

1.clone https://github.com/marekchen/pm-web3
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 Filesnodejsnode.exe,C:UsersmarekAppDataRoamingnpmnode_modulespm2libDaemon.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 Filesnodejsnode.exe,C:UsersmarekAppDataRoamingnpmnode_modulespm2binpm2,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:Usersmarek

--- 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 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Windows stale

Most helpful comment

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"
or
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.

All 20 comments

This is my first time using PM2 and I'm having the same exact issue. Running pm2 start npm -- start creates error

(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually. SyntaxError: Unexpected token : at createScript (vm.js:80:10)

What is inside run in the start directive in your package.json?

I have the same issue
my start directive is
"start": "ts-node -r tsconfig-paths/register src/main.ts ",

I use nest.js
Why can't PM2 start QQ

I'm having the same issue, I think the problem comes when pm2 tries to read the npm.cmd file. When running Get-Command npm I get the path of the npm which my system is using and if I check the content of that file I see the same text from the error.

C:\Users\nicow\development\project [master ≑ +2 ~1 -0 !]> Get-Command npm

CommandType     Name                     Version    Source
-----------     ----                     -------    ------
Application     npm.cmd                  0.0.0.0    C:\Program Files\nodejs\npm.cmd
:: Created by npm, please don't edit manually.
@ECHO OFF

SETLOCAL

SET "NODE_EXE=%~dp0\node.exe"
IF NOT EXIST "%NODE_EXE%" (
  SET "NODE_EXE=node"
)

SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
  SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
)
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
  SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
)

"%NODE_EXE%" "%NPM_CLI_JS%" %*

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"
or
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.

@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?

@msm1089 Did you figure out how to hide the cmd window?

@msm1089 Did you figure out how to hide the cmd window?
β€œnpm i -g pm2-windows-service”,
then add β€œPM2_HOME = xxx/.pm2” to system path ,
”pm2-service-installβ€œ , first step choose "no",
services.msc you will see "pm2"
maybe help you

@nicowernli Thank! save me!

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"
or
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.

Tried this method and solved my problem,verry thinks,
I ran the following code
pm2 start D:\dev\vue\myapp\node_modules\nuxt\bin\nuxt.js --name "myapp" -- run start
It works very well! Thanks again~

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

The issue should be reopen as the error persists

yes this is still an issue. A few messy workarounds, but this feature is worthless on windows.

I'm also having this issue. pm2 version is 4.4.0

Ecosystem.config.js file of:

module.exports = {
    apps: [
        {
            name: "cms",
            script: "npm",
            args: "start"
        }
    ]
};

and running pm2 start in the directory with that file, I get the same pm2 log of

0|cms | C:\PROGRAM FILES\NODEJS\NPM.CMD:1 0|cms | :: Created by npm, please don't edit manually. 0|cms | ^ 0|cms | 0|cms | SyntaxError: Unexpected token ':' 0|cms | at wrapSafe (internal/modules/cjs/loader.js:1054:16) 0|cms | at Module._compile (internal/modules/cjs/loader.js:1102:27) 0|cms | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) 0|cms | at Module.load (internal/modules/cjs/loader.js:986:32) 0|cms | at Function.Module._load (internal/modules/cjs/loader.js:879:14)0|cms | at Object.<anonymous> (C:\Users\Me\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:32:23) 0|cms | at Module._compile (internal/modules/cjs/loader.js:1138:30) 0|cms | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) 0|cms | at Module.load (internal/modules/cjs/loader.js:986:32) 0|cms | at Function.Module._load (internal/modules/cjs/loader.js:879:14)

Same for me, on windows 10 @4.4.0. Very messy workarounds.
Please reopen the ticket.

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:Userssuresh-negiAppDataRoamingnpmnode_modulespm2libProcessContainerFork.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)

Same issue for me.

0|@ftw-clo | SyntaxError: Unexpected token ':'
0|@ftw-clo |     at wrapSafe (internal/modules/cjs/loader.js:1054:16)
0|@ftw-clo |     at Module._compile (internal/modules/cjs/loader.js:1102:27)
0|@ftw-clo |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
0|@ftw-clo |     at Module.load (internal/modules/cjs/loader.js:986:32)
0|@ftw-clo |     at Function.Module._load (internal/modules/cjs/loader.js:879:14)
0|@ftw-clo |     at Object.<anonymous> (C:\Users\msi4\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:32:23)
0|@ftw-clo |     at Module._compile (internal/modules/cjs/loader.js:1138:30)
0|@ftw-clo |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
0|@ftw-clo |     at Module.load (internal/modules/cjs/loader.js:986:32)
0|@ftw-clo |     at Function.Module._load (internal/modules/cjs/loader.js:879:14)

I have the same issue.
This ticket should be reopened.

I have the same issue.
This ticket should be reopened.

try this : pm2 start --name 'myapp' server/index.js -i 4 -f

Still not working :/ I just created a new blank nextjs app and it's not working with pm2.

2|npm      | C:\PROGRAM FILES\NODEJS\NPM.CMD:1
2|npm      | :: Created by npm, please don't edit manually.
2|npm      | ^
2|npm      |
2|npm      | SyntaxError: Unexpected token ':'
2|npm      |     at wrapSafe (internal/modules/cjs/loader.js:979:16)
2|npm      |     at Module._compile (internal/modules/cjs/loader.js:1027:27)
2|npm      |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2|npm      |     at Module.load (internal/modules/cjs/loader.js:928:32)
2|npm      |     at Function.Module._load (internal/modules/cjs/loader.js:769:14)
2|npm      |     at Object.<anonymous> (C:\Program Files\nodejs\node_modules\pm2\lib\ProcessContainerFork.js:33:23)
2|npm      |     at Module._compile (internal/modules/cjs/loader.js:1063:30)
2|npm      |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2|npm      |     at Module.load (internal/modules/cjs/loader.js:928:32)
2|npm      |     at Function.Module._load (internal/modules/cjs/loader.js:769:14)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Β·  3Comments

shaunwarman picture shaunwarman  Β·  3Comments

morfies picture morfies  Β·  3Comments

rajendar38 picture rajendar38  Β·  3Comments

webchaz picture webchaz  Β·  3Comments