部署 nodejs Web 服务的问题。构建以 OK 状态进行,但由于缺少包而无法启动服务。render.com 显示日志文件,但无法通过 shell 访问它。该文件不存在。
在本地,该服务正在运行。如果删除了 node_modules 并安装了 npm 包而没有异议,我可以重现该问题。但在 render.com 部署的情况下并非如此。
有没有解决方案,如何才能启动服务?
构建命令:cd flights-api && npm install
启动命令:cd flights-api && npm run start
(尝试添加npm i --save objection
两个命令,而不改变结果)
package.json
依赖项:
"dependencies": {
"@sentry/node": "^5.11.0",
"apollo-errors": "^1.9.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"graphql-middleware-sentry": "^3.2.1",
"graphql-yoga": "^1.18.3",
"knex": "^0.21.21",
"knex-logger": "^0.1.0",
"lodash": "^4.17.21",
"merge-graphql-schemas": "^1.7.6",
"node-cache": "^5.1.2",
"node-fetch": "^2.6.1",
"objection": "^2.2.15",
"pg": "^8.7.1",
"winston": "^3.2.1"
}
构建日志:
Aug 17 09:36:17 AM ==> Starting service with 'cd flights-api && npm run start'
Aug 17 09:36:20 AM Error: Cannot find module 'objection'
Aug 17 09:36:20 AM Require stack:
Aug 17 09:36:20 AM - /opt/render/project/src/flights-service/models/BaseModel.js
Aug 17 09:36:20 AM - /opt/render/project/src/flights-api/src/index.js
Aug 17 09:36:20 AM at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
Aug 17 09:36:20 AM at Function.Module._load (internal/modules/cjs/loader.js:686:27)
Aug 17 09:36:20 AM at Module.require (internal/modules/cjs/loader.js:848:19)
Aug 17 09:36:20 AM at require (internal/modules/cjs/helpers.js:74:18)
Aug 17 09:36:20 AM at Object.<anonymous> (/opt/render/project/src/flights-service/models/BaseModel.js:1:57)
Aug 17 09:36:20 AM at Module._compile (internal/modules/cjs/loader.js:955:30)
Aug 17 09:36:20 AM at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
Aug 17 09:36:20 AM at Module.load (internal/modules/cjs/loader.js:811:32)
Aug 17 09:36:20 AM at Function.Module._load (internal/modules/cjs/loader.js:723:14)
Aug 17 09:36:20 AM at Module.require (internal/modules/cjs/loader.js:848:19)
Aug 17 09:36:20 AM npm ERR! code ELIFECYCLE
Aug 17 09:36:20 AM npm ERR! errno 1
Aug 17 09:36:20 AM npm ERR! xy-flights-api@1.0.0 start: `node src/index.js`
Aug 17 09:36:20 AM npm ERR! Exit status 1
Aug 17 09:36:20 AM npm ERR!
Aug 17 09:36:20 AM npm ERR! Failed at the xy-flights-api@1.0.0 start script.
Aug 17 09:36:20 AM npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Aug 17 09:36:20 AM
Aug 17 09:36:20 AM npm ERR! A complete log of this run can be found in:
Aug 17 09:36:20 AM npm ERR! /opt/render/.cache/_logs/2021-08-17T07_36_20_174Z-debug.log