node.js - 运行 pm2 日志错误 SyntaxError : Unexpected token

标签 node.js sockets express socket.io serversocket

我想查看我的项目日志

步骤:

  1. 我克隆了一个套接字应用程序。然后我运行 npm install pm2 -g 来安装 pm2

  2. 我运行 pm2 start

它有效。它显示了我的套接字应用程序的表格

但是如果我运行 pm2 logs 来查看日志,就会出现这样的错误:

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

我尝试运行 npm install socket.io express --savenpm install jquery --save,它们是一样的。以上存在错误

我该如何解决这个问题? `

更新:

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

最佳答案

如您在错误消息中所见:

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

尝试删除 C:\PROGRAM FILES\NODEJS\NPM.CMD:1 文件中 { 之后的 :

更新: 我注意到 pm2 正在尝试将 NPM.CMD 文件作为 js 模块执行。将 Windows CMD 文件作为 js 模块运行是不可能的。 如果您在 Windows 上安装了 Git,您可以尝试从 git-bash 运行 pm2,这是一个类似 Linux 的终端。

更新 You can try this answer from others

关于node.js - 运行 pm2 日志错误 SyntaxError : Unexpected token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57975906/

相关文章:

java - 如何在 JUnit 测试中的不同线程中启动 Main.main()

node.js - 发布请求 Axios : Network error

node.js - Amazon Kinesis NodeJS - putRecord 操作过期

javascript - Node JS ENOENT - 没有这样的文件或目录

node.js - 如何获取带有父子关系的json结果?(查看详情)

java - 在 android-j2se 上使用 SSL 与服务器客户端套接字通信

java - Android Socket - 内存泄漏 - 传入消息

javascript - 连接闪存错误消息 : flash is not defined

node.js - 如何在 Node.js 中调用需要用户名和密码的 API

c++ - 如何使用 C++ 在 Node 中编辑歌曲元数据?