Linux中使用PM2运行带有newrelic的项目时Cannot find module './config.js'
发布于 9 年前 作者 thomas0836 7928 次浏览 最后一次编辑是 8 年前 来自 问答

我这个项目 在OX系统环境中 发布 process.env.NODE_ENV = 'production’ 时,没有问题项目可以跑起来 但是在 Linux环境内 使用 PM2运行时

www-0 Error: Cannot find module ‘./config.js’ at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Function.<anonymous> (/nodejs/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21) at Module.require (module.js:365:17) at require (module.js:384:17) at Object.<anonymous> (/home/ec2-user/login/node_modules/newrelic/lib/logger.js:18:14) at Module._compile (module.js:460:26) at Object.Module._extensions…js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) PM2 App name:www id:0 exited with code 255 PM2 Script /home/ec2-user/login/bin/www had too many unstable restarts (15). Stopped. "errored" Write failed: Broken pipe’

在Linux 内ls 项目根目录

app.js config.default.js log newrelic.js public web_router.js bin config.js Makefile node_modules README.md build controllers middlewares package.json test common f2e models proxy views

使用 PM2 来运行的时候会出现这个问题,但是npm start 的话就没有

config.js 是存在的,希望有大神可以指导一下问题在哪里

10 回复

你的问题解决了吗? 我也遇到了这个错 exited with code 255

@imhered 没事啦,运行的文件错了,看package.json的start配置

@thomas0836 额,那我和你还不是一个错。

你好,你的package.json的start怎样配置的?

怎么解决的,能不能说详细一些,谢谢了。新手学习中

@imhered 你解决了吗,怎么弄

@LYmahang123 就是你平时 启动项目的时候是node xxx文件嘛,pm2的时候也是一样 只是吧node 换成 pm2 start xxx。 npm start 是因为 在package.json 中配置了"scripts"

"scripts": {
    "start": "node ./bin/www",
    "test": "mocha-phantomjs ./f2e/index.html"
  }

所以使用 npm start时实质运行的是 node ./bin/www

@LYmahang123 他这个是依赖项没装,我和他不是一个错。

@imhered 如果我没猜错的话,你node的版本应该比较高,换成0.12.X应该就好了。

下次各位如果有类似的找不到文件的问题,就在报错的那一句之前把 process.cwd() 打印出来,这样方便定位问题

回到顶部