我的 express 应用程序中的 heroku 启动脚本有问题,但我的本地主机没有问题。我的 package.json 文件中也有 "dev": "nodemon app"
,但我在全局安装了 nodemon。我在终端中收到 Error: Cannot find module 'dotenv'
错误,但在应用程序日志的 heroku 仪表板中没有看到该错误。当发出 heroku run printenv
命令时,我可以在终端中看到我的环境变量。我还检查了我的依赖项,它们都是最新的。
heroku logs --tail
2021-07-08T21:32:31.468611+00:00 app[api]: Starting process with command `printenv` by user
2021-07-08T21:32:35.901239+00:00 heroku[run.8762]: State changed from starting to up
2021-07-08T21:32:36.023067+00:00 heroku[run.8762]: Awaiting client
2021-07-08T21:32:36.041891+00:00 heroku[run.8762]: Starting process with command `printenv`
2021-07-08T21:32:40.677499+00:00 heroku[run.8762]: Process exited with status 0
2021-07-08T21:32:40.754391+00:00 heroku[run.8762]: State changed from up to complete
2021-07-08T21:34:25.019025+00:00 app[api]: Release v8 created by user
2021-07-08T21:34:25.019025+00:00 app[api]: Remove PORT config vars by user conceptdecorators@email.com
2021-07-08T21:34:26.961008+00:00 heroku[web.1]: State changed from crashed to starting
2021-07-08T21:34:31.276884+00:00 heroku[web.1]: Starting process with command `npm start`
2021-07-08T21:34:34.925122+00:00 app[web.1]:
2021-07-08T21:34:34.925138+00:00 app[web.1]: > davida_client@1.0.0 start /app
2021-07-08T21:34:34.925138+00:00 app[web.1]: > node app
2021-07-08T21:34:34.925139+00:00 app[web.1]:
2021-07-08T21:34:35.520150+00:00 app[web.1]: internal/modules/cjs/loader.js:905
2021-07-08T21:34:35.520168+00:00 app[web.1]: throw err;
2021-07-08T21:34:35.520169+00:00 app[web.1]: ^
2021-07-08T21:34:35.520169+00:00 app[web.1]:
2021-07-08T21:34:35.520169+00:00 app[web.1]: Error: Cannot find module 'dotenv'
2021-07-08T21:34:35.520170+00:00 app[web.1]: Require stack:
2021-07-08T21:34:35.520170+00:00 app[web.1]: - /app/app.js
2021-07-08T21:34:35.520172+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
2021-07-08T21:34:35.520172+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:746:27)
2021-07-08T21:34:35.520174+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2021-07-08T21:34:35.520174+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:92:18)
2021-07-08T21:34:35.520175+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:9:1)
2021-07-08T21:34:35.520175+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-07-08T21:34:35.520175+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-07-08T21:34:35.520176+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2021-07-08T21:34:35.520176+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:14)
2021-07-08T21:34:35.520178+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
2021-07-08T21:34:35.520179+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-07-08T21:34:35.520179+00:00 app[web.1]: requireStack: [ '/app/app.js' ]
2021-07-08T21:34:35.520180+00:00 app[web.1]: }
2021-07-08T21:34:35.562866+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-07-08T21:34:35.563371+00:00 app[web.1]: npm ERR! errno 1
2021-07-08T21:34:35.573398+00:00 app[web.1]: npm ERR! davida_client@1.0.0 start: `node app`
2021-07-08T21:34:35.573640+00:00 app[web.1]: npm ERR! Exit status 1
2021-07-08T21:34:35.574037+00:00 app[web.1]: npm ERR!
2021-07-08T21:34:35.574280+00:00 app[web.1]: npm ERR! Failed at the davida_client@1.0.0 start script.
2021-07-08T21:34:35.574525+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-07-08T21:34:35.581243+00:00 app[web.1]:
2021-07-08T21:34:35.581434+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-07-08T21:34:35.581534+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-07-08T21_34_35_575Z-debug.log
2021-07-08T21:34:35.676142+00:00 heroku[web.1]: Process exited with status 1
2021-07-08T21:34:35.741145+00:00 heroku[web.1]: State changed from starting to crashed
2021-07-08T21:34:35.756155+00:00 heroku[web.1]: State changed from crashed to starting
2021-07-08T21:34:40.754241+00:00 heroku[web.1]: Starting process with command `npm start`
2021-07-08T21:34:44.350725+00:00 app[web.1]:
2021-07-08T21:34:44.350751+00:00 app[web.1]: > davida_client@1.0.0 start /app
2021-07-08T21:34:44.350751+00:00 app[web.1]: > node app
2021-07-08T21:34:44.350751+00:00 app[web.1]:
2021-07-08T21:34:44.948425+00:00 app[web.1]: internal/modules/cjs/loader.js:905
2021-07-08T21:34:44.948549+00:00 app[web.1]: throw err;
2021-07-08T21:34:44.948550+00:00 app[web.1]: ^
2021-07-08T21:34:44.948550+00:00 app[web.1]:
2021-07-08T21:34:44.948557+00:00 app[web.1]: Error: Cannot find module 'dotenv'
2021-07-08T21:34:44.948558+00:00 app[web.1]: Require stack:
2021-07-08T21:34:44.948558+00:00 app[web.1]: - /app/app.js
2021-07-08T21:34:44.948559+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
2021-07-08T21:34:44.948560+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:746:27)
2021-07-08T21:34:44.948561+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2021-07-08T21:34:44.948561+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:92:18)
2021-07-08T21:34:44.948562+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:9:1)
2021-07-08T21:34:44.948562+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-07-08T21:34:44.948562+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-07-08T21:34:44.948563+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2021-07-08T21:34:44.948563+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:14)
2021-07-08T21:34:44.948563+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
2021-07-08T21:34:44.948570+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-07-08T21:34:44.948571+00:00 app[web.1]: requireStack: [ '/app/app.js' ]
2021-07-08T21:34:44.948571+00:00 app[web.1]: }
2021-07-08T21:34:44.965227+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-07-08T21:34:44.965761+00:00 app[web.1]: npm ERR! errno 1
2021-07-08T21:34:44.974771+00:00 app[web.1]: npm ERR! davida_client@1.0.0 start: `node app`
2021-07-08T21:34:44.974966+00:00 app[web.1]: npm ERR! Exit status 1
2021-07-08T21:34:44.975171+00:00 app[web.1]: npm ERR!
2021-07-08T21:34:44.975355+00:00 app[web.1]: npm ERR! Failed at the davida_client@1.0.0 start script.
2021-07-08T21:34:44.975506+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-07-08T21:34:44.995448+00:00 app[web.1]:
2021-07-08T21:34:44.995693+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-07-08T21:34:44.995836+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-07-08T21_34_44_976Z-debug.log
2021-07-08T21:34:45.107605+00:00 heroku[web.1]: Process exited with status 1
2021-07-08T21:34:45.195835+00:00 heroku[web.1]: State changed from starting to crashed
2021-07-08T21:34:45.897918+00:00 heroku[router]: at=error code=H10 desc="App crashed"
package.json
{
"name": "davida_client",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "nodemon app"
},
"repository": {
"type": "git",
"url": "git+https://github.com/conceptdecorators/responsive-example.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/conceptdecorators/responsive-example/issues"
},
"homepage": "https://github.com/conceptdecorators/responsive-example#readme",
"devDependencies": {},
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"request": "^2.88.2"
}
}