将我的Mern应用程序部署到heroku时出现错误“找不到模块'express'”

时间:2020-09-24 18:12:55

标签: reactjs heroku mern

我尝试了所有可以在网上找到的内容,但错误似乎并没有消失。

构建成功,但是我在打开heroku链接时收到应用程序错误。

此外,我已经安装了express,它位于package.json的依赖项中,但仍然出现此错误。

这是我的日志:

2020-09-24T17:56:39.842986+00:00 app[api]: Starting process with command `ls` by user bisma.akram997@gmail.com
2020-09-24T17:56:57.274445+00:00 heroku[run.1354]: State changed from starting to up
2020-09-24T17:56:57.521162+00:00 heroku[run.1354]: Awaiting client
2020-09-24T17:56:57.538472+00:00 heroku[run.1354]: Starting process with command `ls`
2020-09-24T17:57:02.198857+00:00 heroku[run.1354]: Process exited with status 0
2020-09-24T17:57:02.241138+00:00 heroku[run.1354]: State changed from up to complete
2020-09-24T18:03:20.000000+00:00 app[api]: Build started by user bisma.akram997@gmail.com
2020-09-24T18:05:09.000000+00:00 app[api]: Build succeeded
2020-09-24T18:05:09.244048+00:00 app[api]: Release v7 created by user bisma.akram997@gmail.com
2020-09-24T18:05:09.244048+00:00 app[api]: Deploy edbd92ff by user bisma.akram997@gmail.com
2020-09-24T18:05:09.472015+00:00 heroku[web.1]: State changed from crashed to starting
2020-09-24T18:05:22.804906+00:00 heroku[web.1]: Starting process with command `npm run start`
2020-09-24T18:05:25.581716+00:00 app[web.1]:
2020-09-24T18:05:25.581762+00:00 app[web.1]: > restaurant-web-app@1.0.0 start /app
2020-09-24T18:05:25.581763+00:00 app[web.1]: > node ./backend/src/index.js
2020-09-24T18:05:25.581764+00:00 app[web.1]:
2020-09-24T18:05:25.639775+00:00 app[web.1]: internal/modules/cjs/loader.js:968
2020-09-24T18:05:25.639777+00:00 app[web.1]: throw err;
2020-09-24T18:05:25.639777+00:00 app[web.1]: ^
2020-09-24T18:05:25.639778+00:00 app[web.1]:
2020-09-24T18:05:25.639778+00:00 app[web.1]: Error: Cannot find module 'express'
2020-09-24T18:05:25.639778+00:00 app[web.1]: Require stack:
2020-09-24T18:05:25.639779+00:00 app[web.1]: - /app/backend/src/index.js
2020-09-24T18:05:25.639796+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
2020-09-24T18:05:25.639797+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:841:27)
2020-09-24T18:05:25.639798+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1025:19)
2020-09-24T18:05:25.639798+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:72:18)
2020-09-24T18:05:25.639798+00:00 app[web.1]: at Object.<anonymous> (/app/backend/src/index.js:1:16)
2020-09-24T18:05:25.639799+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1137:30)
2020-09-24T18:05:25.639799+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
2020-09-24T18:05:25.639800+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:985:32)
2020-09-24T18:05:25.639800+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:878:14)
2020-09-24T18:05:25.639806+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
2020-09-24T18:05:25.639806+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-09-24T18:05:25.639807+00:00 app[web.1]: requireStack: [ '/app/backend/src/index.js' ]
2020-09-24T18:05:25.639807+00:00 app[web.1]: }
2020-09-24T18:05:25.647398+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-09-24T18:05:25.647713+00:00 app[web.1]: npm ERR! errno 1
2020-09-24T18:05:25.649990+00:00 app[web.1]: npm ERR! restaurant-web-app@1.0.0 start: `node ./backend/src/index.js`
2020-09-24T18:05:25.650080+00:00 app[web.1]: npm ERR! Exit status 1
2020-09-24T18:05:25.650188+00:00 app[web.1]: npm ERR!
2020-09-24T18:05:25.650268+00:00 app[web.1]: npm ERR! Failed at the restaurant-web-app@1.0.0 start script.
2020-09-24T18:05:25.650354+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-09-24T18:05:25.656677+00:00 app[web.1]: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
2020-09-24T18:05:25.657249+00:00 app[web.1]:
2020-09-24T18:05:25.657370+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-09-24T18:05:25.657450+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-09-24T18_05_25_651Z-debug.log
2020-09-24T18:05:25.726178+00:00 heroku[web.1]: Process exited with status 1
2020-09-24T18:05:25.763752+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-24T18:05:25.765941+00:00 heroku[web.1]: State changed from crashed to starting
2020-09-24T18:05:44.679787+00:00 heroku[web.1]: Starting process with command `npm run start`
2020-09-24T18:05:49.087512+00:00 app[web.1]:
2020-09-24T18:05:49.087534+00:00 app[web.1]: > restaurant-web-app@1.0.0 start /app
2020-09-24T18:05:49.087535+00:00 app[web.1]: > node ./backend/src/index.js
2020-09-24T18:05:49.087535+00:00 app[web.1]:
2020-09-24T18:05:49.437587+00:00 app[web.1]: internal/modules/cjs/loader.js:968
2020-09-24T18:05:49.437619+00:00 app[web.1]: throw err;
2020-09-24T18:05:49.437620+00:00 app[web.1]: ^
2020-09-24T18:05:49.437620+00:00 app[web.1]:
2020-09-24T18:05:49.437621+00:00 app[web.1]: Error: Cannot find module 'express'
2020-09-24T18:05:49.437621+00:00 app[web.1]: Require stack:
2020-09-24T18:05:49.437651+00:00 app[web.1]: - /app/backend/src/index.js
2020-09-24T18:05:49.437653+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
2020-09-24T18:05:49.437654+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:841:27)
2020-09-24T18:05:49.437655+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1025:19)
2020-09-24T18:05:49.437655+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:72:18)
2020-09-24T18:05:49.437656+00:00 app[web.1]: at Object.<anonymous> (/app/backend/src/index.js:1:16)
2020-09-24T18:05:49.437656+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1137:30)
2020-09-24T18:05:49.437657+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
2020-09-24T18:05:49.437657+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:985:32)
2020-09-24T18:05:49.437658+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:878:14)
2020-09-24T18:05:49.437659+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
2020-09-24T18:05:49.437659+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-09-24T18:05:49.437660+00:00 app[web.1]: requireStack: [ '/app/backend/src/index.js' ]
2020-09-24T18:05:49.437660+00:00 app[web.1]: }
2020-09-24T18:05:49.500998+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-09-24T18:05:49.501610+00:00 app[web.1]: npm ERR! errno 1
2020-09-24T18:05:49.559185+00:00 app[web.1]: npm ERR! restaurant-web-app@1.0.0 start: `node ./backend/src/index.js`
2020-09-24T18:05:49.571536+00:00 app[web.1]: npm ERR! Exit status 1
2020-09-24T18:05:49.574088+00:00 app[web.1]: npm ERR!
2020-09-24T18:05:49.574374+00:00 app[web.1]: npm ERR! Failed at the restaurant-web-app@1.0.0 start script.
2020-09-24T18:05:49.574676+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-09-24T18:05:49.777113+00:00 app[web.1]: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
2020-09-24T18:05:49.783030+00:00 app[web.1]:
2020-09-24T18:05:49.785017+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-09-24T18:05:49.787998+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-09-24T18_05_49_720Z-debug.log
2020-09-24T18:05:49.914890+00:00 heroku[web.1]: Process exited with status 1
2020-09-24T18:05:49.987388+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-24T18:05:51.141410+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fullstack-restaurant-app97.herokuapp.com request_id=aa5fa856-07c1-4008-8e93-1c480541426a fwd="36.255.44.81" dyno= connect= service= status=503 bytes= protocol=https
2020-09-24T18:05:51.499632+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fullstack-restaurant-app97.herokuapp.com request_id=74130af8-9865-41c2-9df8-d8e832871b72 fwd="36.255.44.81" dyno= connect= service= status=503 bytes= protocol=https

我的package.json文件

{
  "name": "backend",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "cd frontend && npm run build",
    "install-frontend": "cd frontend && npm install",
    "heroku-postbuild": "npm run install-frontend && npm run build",
    "start": "nodemon ./src/index.js",
    "frontend": "cd frontend && npm start"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^5.0.0",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "express-validator": "^6.6.1",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.10.0",
    "multer": "^1.4.2",
    "path": "^0.12.7",
    "shortid": "^2.2.15"
  },
  "devDependencies": {
    "nodemon": "^2.0.4"
  }
}

程序文件 网络:节点./src/index.js

在此感谢我的帮助,

0 个答案:

没有答案