error: Cannot find module '/app/app,js' heroku
error: Cannot find module '/app/app,js' heroku
我的网络在我的本地机器上运行完美,但在 Heroku 中我部署了我的应用程序,但没有任何工作,以及何时:
$ heroku logs --tail
State changed from crashed to starting
Starting process with command `node app.js`
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'express'
Require stack:
- /app/app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/app/app.js:1:17)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/app/app.js' ]
}
目录结构:
-app
-css
-files
-js
-logo
-views
-index.html
-app.js
-composer.json
-package-lock.json
-package.json
-Procfile
过程文件:
web: node app.js
package.json:
{
"name": "app",
"version": "1.0.0",
"engines": {
"node": "14.15.3"
},
"private": "true",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
},
"keywords": [],
"author": "me",
"repository": "appRep",
"license": "ISC",
"devDependencies": {
"chokidar": "^3.5.2",
"express": "^4.17.2",
"fs": "0.0.1-security",
"nodemailer": "^6.7.2",
"nodemon": "^2.0.15",
"path": "^0.12.7"
}
}
.env:(甚至在 .env 文件之前一切都一样)
PORT = 8081
你们有什么想法吗?
提前致谢!!
您的 express
包在 package.json
中的 devDependencies
中列出,请尝试将其移动到 dependencies
中
"dependencies": {
"express": "^4.17.2"
}
devDependencies
应该只列出对部署在生产环境 (Heroku) 的应用程序来说不是必需的包。可能需要将更多包移动到 dependencies
,而不仅仅是 express
。
确保 express 安装在 Heroku 上。
您应该将 express
添加到 package.json
文件
中的 dependencies
对象
我的网络在我的本地机器上运行完美,但在 Heroku 中我部署了我的应用程序,但没有任何工作,以及何时:
$ heroku logs --tail
State changed from crashed to starting
Starting process with command `node app.js`
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'express'
Require stack:
- /app/app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/app/app.js:1:17)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/app/app.js' ]
}
目录结构:
-app
-css
-files
-js
-logo
-views
-index.html
-app.js
-composer.json
-package-lock.json
-package.json
-Procfile
过程文件:
web: node app.js
package.json:
{
"name": "app",
"version": "1.0.0",
"engines": {
"node": "14.15.3"
},
"private": "true",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
},
"keywords": [],
"author": "me",
"repository": "appRep",
"license": "ISC",
"devDependencies": {
"chokidar": "^3.5.2",
"express": "^4.17.2",
"fs": "0.0.1-security",
"nodemailer": "^6.7.2",
"nodemon": "^2.0.15",
"path": "^0.12.7"
}
}
.env:(甚至在 .env 文件之前一切都一样)
PORT = 8081
你们有什么想法吗? 提前致谢!!
您的 express
包在 package.json
中的 devDependencies
中列出,请尝试将其移动到 dependencies
中
"dependencies": {
"express": "^4.17.2"
}
devDependencies
应该只列出对部署在生产环境 (Heroku) 的应用程序来说不是必需的包。可能需要将更多包移动到 dependencies
,而不仅仅是 express
。
确保 express 安装在 Heroku 上。
您应该将 express
添加到 package.json
文件
dependencies
对象