"Cannot find module" 在 Heroku 或 RedHat Openshift Online 上部署 node.js 程序时出现错误消息
"Cannot find module" error message when deploying a node.js program on Heroku or RedHat Openshift Online
`Environment:
DEV_MODE=false
NODE_ENV=production
DEBUG_PORT=5858
Launching via npm...
npm info it worked if it ends with ok
npm info using npm@5.6.0
npm info using node@v8.9.4
npm info lifecycle SuperCineBot@1.0.0~prestart: SuperCineBot@1.0.0
npm info lifecycle SuperCineBot@1.0.0~start: SuperCineBot@1.0.0
SuperCineBot@1.0.0 start /opt/app-root/src
node main
module.js:540
throw err;
^
Error: Cannot find module './dnssec'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/opt/app-root/src/node_modules/sshpk/lib/formats/auto.js:16:14)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
npm info lifecycle SuperCineBot@1.0.0~start: Failed to exec start script
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! SuperCineBot@1.0.0 start: `node main`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the SuperCineBot@1.0.0 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! /opt/app-root/src/.npm/_logs/2018-05-07T20_59_43_900Z-debug.log
`
您好,
我知道这个问题已经发布了很多次,但是我在 Heroku 或 Redhat Openshift Online 上部署我的代码 (https://github.com/yukinoe/kizabot) 时遇到了问题。即使“./dnssec”模块位于 node_modules 文件夹中,我也会收到相同的错误消息。
有人有想法吗?
感谢您的帮助。
您正在通过相对路径导入,因此您需要确保 dnssec.js
存在于进行导入的任何人旁边(在您的情况下可能是 index.js
)。
因此您的层次结构需要看起来像这样:
./src
index.js
dnssec.js
node_modules
不适合这个,因为从那里进口不应该是相对的。
`Environment:
DEV_MODE=false
NODE_ENV=production
DEBUG_PORT=5858
Launching via npm...
npm info it worked if it ends with ok
npm info using npm@5.6.0
npm info using node@v8.9.4
npm info lifecycle SuperCineBot@1.0.0~prestart: SuperCineBot@1.0.0
npm info lifecycle SuperCineBot@1.0.0~start: SuperCineBot@1.0.0
SuperCineBot@1.0.0 start /opt/app-root/src
node main
module.js:540
throw err;
^
Error: Cannot find module './dnssec'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/opt/app-root/src/node_modules/sshpk/lib/formats/auto.js:16:14)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
npm info lifecycle SuperCineBot@1.0.0~start: Failed to exec start script
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! SuperCineBot@1.0.0 start: `node main`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the SuperCineBot@1.0.0 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! /opt/app-root/src/.npm/_logs/2018-05-07T20_59_43_900Z-debug.log
`
您好,
我知道这个问题已经发布了很多次,但是我在 Heroku 或 Redhat Openshift Online 上部署我的代码 (https://github.com/yukinoe/kizabot) 时遇到了问题。即使“./dnssec”模块位于 node_modules 文件夹中,我也会收到相同的错误消息。
有人有想法吗?
感谢您的帮助。
您正在通过相对路径导入,因此您需要确保 dnssec.js
存在于进行导入的任何人旁边(在您的情况下可能是 index.js
)。
因此您的层次结构需要看起来像这样:
./src
index.js
dnssec.js
node_modules
不适合这个,因为从那里进口不应该是相对的。