拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 错误:找不到模块'/app/app,js'heroku

错误:找不到模块'/app/app,js'heroku

白鹭 - 2022-01-23 2126 0 0

我的网络在我的本地机器上完美运行,但在 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

包.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

你们有什么想法吗?先感谢您!!

uj5u.com热心网友回复:

您的express包裹已在devDependencies列出package.json,请尝试将其移动到dependencies这样

"dependencies": {
  "express": "^4.17.2"
}

devDependencies应该只列出对生产中部署的应用程序(Heroku)不是必需的包。这可能是必要之举更包dependencies不但express

uj5u.com热心网友回复:

确保在 Heroku 上安装了 express。您应该添加express档案中dependencies物件package.json

标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *