run pm2 logs error SyntaxError: Unexpected token

别等时光非礼了梦想. 提交于 2021-02-11 15:49:54

问题


I want to see logs of my project

Steps :

  1. I clone a socket app. Then I run npm install pm2 -g to install pm2

  2. I run pm2 start

It works. It display a table of my socket app

But if I run pm2 logs to see logs, there exist error like this :

1|mycompany | C:\PROGRAM FILES\NODEJS\NPM.CMD:1
1|mycompany | (function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
1|mycompany |                                                               ^
1|mycompany |
1|mycompany | SyntaxError: Unexpected token :
1|mycompany |     at new Script (vm.js:79:7)
1|mycompany |     at createScript (vm.js:251:10)
1|mycompany |     at Object.runInThisContext (vm.js:303:10)
1|mycompany |     at Module._compile (internal/modules/cjs/loader.js:657:28)
1|mycompany |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
1|mycompany |     at Module.load (internal/modules/cjs/loader.js:599:32)
1|mycompany |     at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
1|mycompany |     at Function.Module._load (internal/modules/cjs/loader.js:530:3)
1|mycompany |     at C:\Users\Chelsea\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainer.js:295:23
1|mycompany |     at C:\Users\Chelsea\AppData\Roaming\npm\node_modules\pm2\node_modules\async\internal\once.js:12:16

I try to run npm install socket.io express --save and npm install jquery --save, it's the same. there exist error above

How can I solve this problem? `

Update :

C:\PROGRAM FILES\NODEJS\NPM.CMD like this :

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

回答1:


As you can see in the error message:

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

Try to remove : after { in C:\PROGRAM FILES\NODEJS\NPM.CMD:1 file.

Update: I noticed that pm2 is tring to execute the NPM.CMD file as a js module. That's not possible for running a windows CMD file as a js module. If you installed Git on your windows, you can try running the pm2 from the git-bash which was a Linux-like terminal.

Update You can try this answer from others



来源:https://stackoverflow.com/questions/57975906/run-pm2-logs-error-syntaxerror-unexpected-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!