pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

`pm2 start npm -- start` error

Open marekchen opened this issue 8 years ago • 45 comments

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 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 │ └──────────┴────┴──────┴─────┴─────────┴─────────┴────────┴─────┴────────┴─────────┴──────────┘

marekchen avatar May 11 '18 03:05 marekchen

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)

hufftheweevil avatar May 15 '18 17:05 hufftheweevil

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

Unitech avatar May 17 '18 16:05 Unitech

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

lalalalaluk avatar Jun 12 '18 06:06 lalalalaluk

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%" %*

nicowernli avatar Jul 19 '18 11:07 nicowernli

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 avatar Apr 11 '19 08:04 nguiard

@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 avatar May 02 '19 21:05 msm1089

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

joelgb2194 avatar Jun 19 '19 15:06 joelgb2194

@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

Feng-xiaoji avatar Jul 02 '19 14:07 Feng-xiaoji

@nicowernli Thank! save me!

HerokunTan avatar Sep 27 '19 10:09 HerokunTan

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~

senher avatar May 20 '20 05:05 senher

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.

stale[bot] avatar Jun 19 '20 06:06 stale[bot]

The issue should be reopen as the error persists

Silventino avatar Aug 02 '20 21:08 Silventino

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

Naphier avatar Aug 08 '20 17:08 Naphier

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      | :: 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)

dlinning-jockey avatar Aug 18 '20 14:08 dlinning-jockey

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

triplevoid avatar Aug 21 '20 09:08 triplevoid

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)

SureshNegi avatar Aug 26 '20 19:08 SureshNegi

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)

dmitrijs-pavlovs-dev avatar Sep 04 '20 08:09 dmitrijs-pavlovs-dev

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

vitorbraga avatar Sep 28 '20 22:09 vitorbraga

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

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

senher avatar Sep 29 '20 01:09 senher

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)

xairoo avatar Dec 21 '20 22:12 xairoo