CNode

Linux中使用PM2运行带有newrelic的项目时Cannot find module './config.js'

问答
Tthomas0836发布于11 年前最后回复11 年前10 回复9597 浏览0 收藏

我这个项目 在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. (/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. (/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)

I
im-here#1·11 年前

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

T
thomas0836#2·11 年前
引用 im-here你的问题解决了吗? 我也遇到了这个错 exited with code 255

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

I
im-here#3·11 年前
引用 thomas0836@imhered 没事啦,运行的文件错了,看package.json的start配置

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

3
39Er#4·11 年前

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

L
LYmahang123#5·11 年前

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

L
LYmahang123#6·11 年前
引用 im-here@thomas0836 额,那我和你还不是一个错。

@imhered 你解决了吗,怎么弄

T
thomas0836#7·11 年前
引用 LYmahang123@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

I
im-here#8·11 年前
引用 LYmahang123@imhered 你解决了吗,怎么弄

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

H
haozxuan#9·11 年前
引用 im-here@LYmahang123 他这个是依赖项没装,我和他不是一个错。

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

A
alsotang#10·11 年前

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

参与回复
登录后即可参与回复。登录