[英]Node app is throwing error in production but not in dev with same package?
I am trying to deploy my first node application to production server in a shared hosting platform but whenever I run the start script I get the following error message:我正在尝试将我的第一个节点应用程序部署到共享托管平台中的生产服务器,但是每当我运行启动脚本时,我都会收到以下错误消息:
returncode: 1 stdout:返回码:1 标准输出:
thechoicebox-backend@1.0.0 dev /home/ftijpnql/tcb thechoicebox-backend@1.0.0 dev /home/ftijpnql/tcb
node server.js --scripts-prepend-node-path stderr: npm WARN lifecycle The node binary used for scripts is node server.js --scripts-prepend-node-path stderr: npm WARN Lifecycle 用于脚本的节点二进制文件是
/home/ftijpnql/nodevenv/tcb/14/bin/node but npm is using /opt/alt/alt-nodejs14/root/usr/bin/node itself. /home/ftijpnql/nodevenv/tcb/14/bin/node 但 npm 正在使用 /opt/alt/alt-nodejs14/root/usr/bin/node 本身。 Use the
--scripts-prepend-node-path
option to include the path for the node binary npm was executed with.使用--scripts-prepend-node-path
选项包含执行节点二进制 npm 的路径。 internal/modules/cjs/loader.js:905内部/模块/cjs/loader.js:905
throw err;抛出错误; ^ ^Error: Cannot find module '/home/ftijpnql/nodevenv/tcb/14/lib/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node' Require stack:错误:找不到模块 '/home/ftijpnql/nodevenv/tcb/14/lib/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node' 需要堆栈:
- /home/ftijpnql/nodevenv/tcb/14/lib/node_modules/bcrypt/bcrypt.js /home/ftijpnql/nodevenv/tcb/14/lib/node_modules/bcrypt/bcrypt.js
- /home/ftijpnql/tcb/src/controller/admin-auth.controller.js /home/ftijpnql/tcb/src/controller/admin-auth.controller.js
- /home/ftijpnql/tcb/src/app.js /home/ftijpnql/tcb/src/app.js
- /home/ftijpnql/tcb/server.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) at Function.Module._load (internal/modules/cjs/loader.js:746:27) at Module.require (internal/modules/cjs/loader.js:974:19) at require (internal/modules/cjs/helpers.js:92:18) at Object. /home/ftijpnql/tcb/server.js 在 Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) 在 Function.Module._load (internal/modules/cjs/loader.js:746: 27) 在 Module.require (internal/modules/cjs/loader.js:974:19) 在 require (internal/modules/cjs/helpers.js:92:18) 在 Object。 (/home/ftijpnql/nodevenv/tcb/14/lib/node_modules/bcrypt/bcrypt.js:6:16) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:14) at Module.require (internal/modules/cjs/loader.js:974:19) { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/ftijpnql/nodevenv/tcb/14/lib/node_modules/bcrypt/bcrypt.js', '/home/ftijpnql/tcb/src/controller/admin-auth.controller.js', '/home/ftijpnql/tcb/src/app.js', '/home/ftijpnql/tcb/server.js' ] } npm ERR! (/home/ftijpnql/nodevenv/tcb/14/lib/node_modules/bcrypt/bcrypt.js:6:16) 在 Object.Module 的 Module._compile (internal/modules/cjs/loader.js:1085:14)。 _extensions..js (internal/modules/cjs/loader.js:1114:10) 在 Module.load (internal/modules/cjs/loader.js:950:32) 在 Function.Module._load (internal/modules/cjs) /loader.js:790:14) 在 Module.require (internal/modules/cjs/loader.js:974:19) { 代码:'MODULE_NOT_FOUND',requireStack:['/home/ftijpnql/nodevenv/tcb/14/ lib/node_modules/bcrypt/bcrypt.js', '/home/ftijpnql/tcb/src/controller/admin-auth.controller.js', '/home/ftijpnql/tcb/src/app.js', '/home /ftijpnql/tcb/server.js' ] } npm ERR! code ELIFECYCLE npm ERR!代码 ELIFECYCLE npm ERR! errno 1 npm ERR!错误号 1 npm 错误号! thechoicebox-backend@1.0.0 dev:
node server.js --scripts-prepend-node-path
npm ERR! thechoicebox-backend@1.0.0 dev:node server.js --scripts-prepend-node-path
npm ERR! Exit status 1 npm ERR!退出状态 1 npm ERR! npm ERR!错误! Failed at the thechoicebox-backend@1.0.0 dev script.在 thechoicebox-backend@1.0.0 开发脚本中失败。 npm ERR!错误! This is probably not a problem with npm.这可能不是 npm 的问题。 There is likely additional logging output above.上面可能有额外的日志输出。npm ERR!错误! A complete log of this run can be found in: npm ERR!可以在以下位置找到此运行的完整日志:npm ERR!
/home/ftijpnql/.npm/_logs/2021-10-05T16_19_33_946Z-debug.log /home/ftijpnql/.npm/_logs/2021-10-05T16_19_33_946Z-debug.log
Although with same dependency and node version the project is running in my system.尽管具有相同的依赖项和节点版本,但该项目正在我的系统中运行。
package.json包.json
{
"name": "thechoicebox-backend",
"version": "1.0.0",
"engines": {
"node": "14.7.0"
},
"description": "",
"main": "index.js",
"scripts": {
"start": "node dist/app.js",
"dev": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.1",
"body-parser": "^1.19.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"http": "0.0.1-security",
"jsonwebtoken": "^8.5.1",
"multer": "^1.4.2",
"mysql2": "^2.2.5",
"sequelize": "^6.6.2"
},
"devDependencies": {
"nodemon": "^2.0.7"
}
}
My production node version is 14.xx not same as in package.json file as that was not present there.我的生产节点版本是 14.xx 与 package.json 文件中的不同,因为那里不存在。
Kindly help me out I am stuck !请帮助我,我被卡住了!
I had a "similar" problem with Node when I was debugging and I wanted to change to dev using nodemon.我在调试时遇到了 Node 的“类似”问题,我想使用 nodemon 更改为 dev。
/dist
folder检查您的/dist
文件夹
This definitely helped me.这绝对帮助了我。 Hope this helps you too.希望这对你也有帮助。
Something went wrong in the package installation包安装出现问题
you can do for re-install:您可以重新安装:
rm -rf node_modules
then然后
npm install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.