简体   繁体   中英

error: Cannot find module '/app/app,js' heroku

My web works perfectly on my local machine and all that, but in Heroku I deployed my app and nothing is working, and when: $ 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' ]
}

directory structure:

-app
 -css
 -files
 -js
 -logo
 -views
 -index.html
-app.js
-composer.json
-package-lock.json
-package.json
-Procfile

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: (even before the.env file everything was the same)

PORT = 8081

Do you guys have any idea? Thank you in advance!!

Make sure the express installed on Heroku. You should add express to the dependencies object in package.json file

Your express package is listed in devDependencies in package.json , try moving it to dependencies like so

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

devDependencies should list only packages which are not essential for app deployed in production (Heroku). It might be necessary to move more packages to dependencies not only express .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM