Heroku Error: Cannot find module './common'
Heroku Error: Cannot find module './common'
我试图将一个实践项目部署到 Heroku,它被部署了。但是有一个应用程序错误,阻止应用程序在服务器上 运行。在 运行ning heroku logs
.
之后,我得到了一些关于错误的详细信息
2022-03-07T01:25:09.883329+00:00 app[web.1]: node:internal/modules/cjs/loader:936
2022-03-07T01:25:09.883379+00:00 app[web.1]: throw err;
2022-03-07T01:25:09.883379+00:00 app[web.1]: ^
2022-03-07T01:25:09.883379+00:00 app[web.1]:
2022-03-07T01:25:09.883380+00:00 app[web.1]: Error: Cannot find module './common'
2022-03-07T01:25:09.883380+00:00 app[web.1]: Require stack:
2022-03-07T01:25:09.883380+00:00 app[web.1]: - /app/node_modules/debug/src/node.js
2022-03-07T01:25:09.883381+00:00 app[web.1]: - /app/node_modules/debug/src/index.js
2022-03-07T01:25:09.883381+00:00 app[web.1]: - /app/node_modules/mquery/lib/mquery.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/promise_provider.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/utils.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/statemachine.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/lib/internal.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/lib/document.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/lib/index.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/index.js
2022-03-07T01:25:09.883386+00:00 app[web.1]: - /app/db/connect.js
2022-03-07T01:25:09.883386+00:00 app[web.1]: - /app/app.js
2022-03-07T01:25:09.883387+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-03-07T01:25:09.883387+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-03-07T01:25:09.883388+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-03-07T01:25:09.883388+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-03-07T01:25:09.883388+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/debug/src/node.js:240:18)
2022-03-07T01:25:09.883389+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1103:14)
2022-03-07T01:25:09.883389+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
2022-03-07T01:25:09.883389+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-03-07T01:25:09.883390+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-03-07T01:25:09.883390+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2022-03-07T01:25:09.883390+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-03-07T01:25:09.883390+00:00 app[web.1]: requireStack: [
2022-03-07T01:25:09.883391+00:00 app[web.1]: '/app/node_modules/debug/src/node.js',
2022-03-07T01:25:09.883391+00:00 app[web.1]: '/app/node_modules/debug/src/index.js',
2022-03-07T01:25:09.883391+00:00 app[web.1]: '/app/node_modules/mquery/lib/mquery.js',
2022-03-07T01:25:09.883392+00:00 app[web.1]: '/app/node_modules/mongoose/lib/promise_provider.js',
2022-03-07T01:25:09.883392+00:00 app[web.1]: '/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/utils.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/statemachine.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/internal.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/document.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/node_modules/mongoose/lib/index.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/node_modules/mongoose/index.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/db/connect.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/app.js'
2022-03-07T01:25:09.883394+00:00 app[web.1]: ]
2022-03-07T01:25:09.883395+00:00 app[web.1]: }
2022-03-07T01:25:10.033008+00:00 heroku[web.1]: Process exited with status 1
2022-03-07T01:25:10.264584+00:00 heroku[web.1]: State changed from starting to crashed
我已经使用 npm install common --save
单独安装了 common
软件包,但这并没有解决问题。还删除了 node_modules
并重新安装了所有模块。但是似乎没有任何效果。我已经在互联网上搜索了这个问题的答案,但还没有找到任何有效的方法。
我的 package.json
看起来像这样,
{
"name": "starter-again",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"dotenv": "^16.0.0",
"nodemon": "^2.0.15"
},
"dependencies": {
"common": "^0.2.5",
"debug": "^4.3.3",
"express": "^4.17.3",
"mongoose": "^6.2.4"
},
"engines": {
"node": "16.14.0"
},
}
关于如何解决这个错误有什么建议吗?
我通过在原来存在的 .gitignore
文件夹中没有 node_modules
解决了这个问题。
我试图将一个实践项目部署到 Heroku,它被部署了。但是有一个应用程序错误,阻止应用程序在服务器上 运行。在 运行ning heroku logs
.
2022-03-07T01:25:09.883329+00:00 app[web.1]: node:internal/modules/cjs/loader:936
2022-03-07T01:25:09.883379+00:00 app[web.1]: throw err;
2022-03-07T01:25:09.883379+00:00 app[web.1]: ^
2022-03-07T01:25:09.883379+00:00 app[web.1]:
2022-03-07T01:25:09.883380+00:00 app[web.1]: Error: Cannot find module './common'
2022-03-07T01:25:09.883380+00:00 app[web.1]: Require stack:
2022-03-07T01:25:09.883380+00:00 app[web.1]: - /app/node_modules/debug/src/node.js
2022-03-07T01:25:09.883381+00:00 app[web.1]: - /app/node_modules/debug/src/index.js
2022-03-07T01:25:09.883381+00:00 app[web.1]: - /app/node_modules/mquery/lib/mquery.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/promise_provider.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/utils.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/statemachine.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/lib/internal.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/lib/document.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/lib/index.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/index.js
2022-03-07T01:25:09.883386+00:00 app[web.1]: - /app/db/connect.js
2022-03-07T01:25:09.883386+00:00 app[web.1]: - /app/app.js
2022-03-07T01:25:09.883387+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-03-07T01:25:09.883387+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-03-07T01:25:09.883388+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-03-07T01:25:09.883388+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-03-07T01:25:09.883388+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/debug/src/node.js:240:18)
2022-03-07T01:25:09.883389+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1103:14)
2022-03-07T01:25:09.883389+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
2022-03-07T01:25:09.883389+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-03-07T01:25:09.883390+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-03-07T01:25:09.883390+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2022-03-07T01:25:09.883390+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-03-07T01:25:09.883390+00:00 app[web.1]: requireStack: [
2022-03-07T01:25:09.883391+00:00 app[web.1]: '/app/node_modules/debug/src/node.js',
2022-03-07T01:25:09.883391+00:00 app[web.1]: '/app/node_modules/debug/src/index.js',
2022-03-07T01:25:09.883391+00:00 app[web.1]: '/app/node_modules/mquery/lib/mquery.js',
2022-03-07T01:25:09.883392+00:00 app[web.1]: '/app/node_modules/mongoose/lib/promise_provider.js',
2022-03-07T01:25:09.883392+00:00 app[web.1]: '/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/utils.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/statemachine.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/internal.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/document.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/node_modules/mongoose/lib/index.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/node_modules/mongoose/index.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/db/connect.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/app.js'
2022-03-07T01:25:09.883394+00:00 app[web.1]: ]
2022-03-07T01:25:09.883395+00:00 app[web.1]: }
2022-03-07T01:25:10.033008+00:00 heroku[web.1]: Process exited with status 1
2022-03-07T01:25:10.264584+00:00 heroku[web.1]: State changed from starting to crashed
我已经使用 npm install common --save
单独安装了 common
软件包,但这并没有解决问题。还删除了 node_modules
并重新安装了所有模块。但是似乎没有任何效果。我已经在互联网上搜索了这个问题的答案,但还没有找到任何有效的方法。
我的 package.json
看起来像这样,
{
"name": "starter-again",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"dotenv": "^16.0.0",
"nodemon": "^2.0.15"
},
"dependencies": {
"common": "^0.2.5",
"debug": "^4.3.3",
"express": "^4.17.3",
"mongoose": "^6.2.4"
},
"engines": {
"node": "16.14.0"
},
}
关于如何解决这个错误有什么建议吗?
我通过在原来存在的 .gitignore
文件夹中没有 node_modules
解决了这个问题。