【问题标题】:NPM trouble starting Mongo from script从脚本启动 Mongo 的 NPM 问题
【发布时间】:2018-03-15 07:41:33
【问题描述】:

我正在尝试在 Debian 9 中运行一个名为 Streetmix 的项目。我已尽我所能遵循安装说明。因此,当我在 streetmix 文件夹中使用 NPM Start 命令(带或不带 sudo)时,我得到:

> streetmix@1.3.0 prestart /home/dpowell/streetmix/streetmix
> npm run mongo:start


> streetmix@1.3.0 mongo:start /home/dpowell/streetmix/streetmix
> mongod --fork --logpath /dev/null

about to fork child process, waiting until server is ready for connections.
forked process: 2076
ERROR: child process failed, exited with error number 100
npm ERR! code ELIFECYCLE
npm ERR! errno 100
npm ERR! streetmix@1.3.0 mongo:start: `mongod --fork --logpath /dev/null`
npm ERR! Exit status 100
npm ERR! 
npm ERR! Failed at the streetmix@1.3.0 mongo:start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-03-15T06_55_52_710Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 100
npm ERR! streetmix@1.3.0 prestart: `npm run mongo:start`
npm ERR! Exit status 100
npm ERR! 
npm ERR! Failed at the streetmix@1.3.0 prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-03-15T06_55_52_721Z-debug.log

Streetmix 的说明说我需要将 mongodb/bin 文件夹添加到 $PATH,但是命令 mongo --version 可以在任何文件夹中使用,我认为这意味着因为 mongo 在 usr/ bin 文件夹,它已经在我的 $PATH 中,对吗? (我还启动了 mongod,然后启动了 Mongo shell 以确保它正常工作。我还创建了 /data/db 文件夹。

有人知道我的问题可能是什么吗?

以下是错误末尾提到的日志内容:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
2 info using npm@5.6.0
3 info using node@v8.10.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle streetmix@1.3.0~prestart: streetmix@1.3.0
6 verbose lifecycle streetmix@1.3.0~prestart: unsafe-perm in lifecycle true
7 verbose lifecycle streetmix@1.3.0~prestart: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/dpowell/streetmix/streetmix/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
8 verbose lifecycle streetmix@1.3.0~prestart: CWD: /home/dpowell/streetmix/streetmix
9 silly lifecycle streetmix@1.3.0~prestart: Args: [ '-c', 'npm run mongo:start' ]
10 silly lifecycle streetmix@1.3.0~prestart: Returned: code: 100  signal: null
11 info lifecycle streetmix@1.3.0~prestart: Failed to exec prestart script
12 verbose stack Error: streetmix@1.3.0 prestart: `npm run mongo:start`
12 verbose stack Exit status 100
12 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
12 verbose stack     at emitTwo (events.js:126:13)
12 verbose stack     at EventEmitter.emit (events.js:214:7)
12 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
12 verbose stack     at emitTwo (events.js:126:13)
12 verbose stack     at ChildProcess.emit (events.js:214:7)
12 verbose stack     at maybeClose (internal/child_process.js:925:16)
12 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
13 verbose pkgid streetmix@1.3.0
14 verbose cwd /home/dpowell/streetmix/streetmix
15 verbose Linux 4.9.0-6-amd64
16 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
17 verbose node v8.10.0
18 verbose npm  v5.6.0
19 error code ELIFECYCLE
20 error errno 100
21 error streetmix@1.3.0 prestart: `npm run mongo:start`
21 error Exit status 100
22 error Failed at the streetmix@1.3.0 prestart script.
22 error This is probably not a problem with npm. There is likely additional logging output above.
23 verbose exit [ 100, true ]

【问题讨论】:

  • 手动启动mongod --logpath /dev/null以获取详细错误。
  • @AlexBlex 这就是奇怪的部分!从同一路径运行终端,该命令不会产生错误!
  • 那么输出是什么?
  • 该命令没有输出,但如果我之后运行“sudo service mongod status”命令,我会得到: mongod.service - 高性能、无模式的面向文档的数据库已加载:加载(/lib/systemd/system/mongod.service;禁用;供应商预设:活动:不活动(死)
  • 对不起伙计,你看过我的第一条评论了吗?我让你在终端中执行确切的命令mongod --logpath /dev/null。如果没有输出,则需要重新安装 mongodb。

标签: node.js mongodb npm debian


【解决方案1】:

问题出在 --fork 上。我遇到了同样的问题。

您需要做的是从 package.json 中删除 prestart 和 mongo:start 脚本,在单独的终端中打开 mongodb。然后就可以正常运行 npm start 了!

附:确保你没有提交这个修改过的文件

【讨论】:

  • 多么奇怪的错误。我想知道是否有修复或解决方法。感谢您对 Ayush 的洞察!
  • 确实,--fork 是一个 linux 命令,用于创建子进程并在后台运行它。在 Windows 上运行它时,我必须修改脚本。虽然在linux上应该没有问题
猜你喜欢
  • 2013-10-12
  • 1970-01-01
  • 2020-06-22
  • 2019-04-13
  • 1970-01-01
  • 2019-04-28
  • 1970-01-01
  • 2022-01-11
  • 2018-07-21
相关资源
最近更新 更多