错误:将节点应用程序推送到Heroku时找不到模块“表达”

时间:2019-02-26 05:46:20

标签: node.js reactjs heroku deployment package.json

一个完整的新手,可以构建节点应用程序并部署到Heroku。我用React.js(create-react-app),Node和Express构建了我的应用程序。

在本地一切正常,但是在推送到Heroku时出现以下错误。

2019-02-26T05:25:34.482091+00:00 app[web.1]: 
2019-02-26T05:25:34.578028+00:00 app[web.1]: internal/modules/cjs/loader.js:583
2019-02-26T05:25:34.578031+00:00 app[web.1]: throw err;
2019-02-26T05:25:34.578033+00:00 app[web.1]: ^
2019-02-26T05:25:34.578034+00:00 app[web.1]: 
2019-02-26T05:25:34.578036+00:00 app[web.1]: Error: Cannot find module 'express'
2019-02-26T05:25:34.578049+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
2019-02-26T05:25:34.578051+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:507:25)
2019-02-26T05:25:34.578053+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-02-26T05:25:34.578054+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)
2019-02-26T05:25:34.578056+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:1:79)
2019-02-26T05:25:34.578057+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:689:30)
2019-02-26T05:25:34.578059+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
2019-02-26T05:25:34.578060+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:599:32)
2019-02-26T05:25:34.578062+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
2019-02-26T05:25:34.578064+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:530:3)
2019-02-26T05:25:34.583038+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-02-26T05:25:34.583529+00:00 app[web.1]: npm ERR! errno 1
2019-02-26T05:25:34.584697+00:00 app[web.1]: npm ERR! zenform2@1.0.0 start: `node ./bin/www`
2019-02-26T05:25:34.584932+00:00 app[web.1]: npm ERR! Exit status 1
2019-02-26T05:25:34.585268+00:00 app[web.1]: npm ERR!
2019-02-26T05:25:34.585524+00:00 app[web.1]: npm ERR! Failed at the zenform2@1.0.0 start script.
2019-02-26T05:25:34.585778+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-02-26T05:25:34.590694+00:00 app[web.1]: 
2019-02-26T05:25:34.590929+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-02-26T05:25:34.591075+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-02-26T05_25_34_587Z-debug.log
2019-02-26T05:25:34.657660+00:00 heroku[web.1]: Process exited with status 1
2019-02-26T05:25:41.203272+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.zenform.co request_id=7ae2bd9a-1fe6-405d-8507-b65575e34254 fwd="76.102.21.229" dyno= connect= service= status=503 bytes= protocol=http
2019-02-26T05:32:12.000000+00:00 app[api]: Build started by user zenform.co@gmail.com
2019-02-26T05:34:04.264186+00:00 heroku[web.1]: State changed from crashed to starting
2019-02-26T05:34:04.060723+00:00 app[api]: Deploy ec860d98 by user zenform.co@gmail.com
2019-02-26T05:34:04.060723+00:00 app[api]: Release v73 created by user zenform.co@gmail.com
2019-02-26T05:34:04.000000+00:00 app[api]: Build succeeded
2019-02-26T05:34:19.208996+00:00 heroku[web.1]: Starting process with command `npm start`
2019-02-26T05:34:22.706524+00:00 heroku[web.1]: State changed from starting to crashed
2019-02-26T05:34:22.737586+00:00 heroku[web.1]: State changed from crashed to starting
2019-02-26T05:34:22.557721+00:00 app[web.1]: internal/modules/cjs/loader.js:583
2019-02-26T05:34:22.557738+00:00 app[web.1]: throw err;
2019-02-26T05:34:22.557739+00:00 app[web.1]: ^
2019-02-26T05:34:22.557740+00:00 app[web.1]: 
2019-02-26T05:34:22.557742+00:00 app[web.1]: Error: Cannot find module 'express'
2019-02-26T05:34:22.557744+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
2019-02-26T05:34:22.557745+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:507:25)
2019-02-26T05:34:22.557747+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-02-26T05:34:22.557748+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)
2019-02-26T05:34:22.557750+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:1:79)
2019-02-26T05:34:22.557752+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:689:30)
2019-02-26T05:34:22.557753+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
2019-02-26T05:34:22.557755+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:599:32)
2019-02-26T05:34:22.557757+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
2019-02-26T05:34:22.557758+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:530:3)
2019-02-26T05:34:22.568138+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-02-26T05:34:22.568712+00:00 app[web.1]: npm ERR! errno 1
2019-02-26T05:34:22.570298+00:00 app[web.1]: npm ERR! zenform2@1.0.0 start: `node ./bin/www`
2019-02-26T05:34:22.570546+00:00 app[web.1]: npm ERR! Exit status 1
2019-02-26T05:34:22.570909+00:00 app[web.1]: npm ERR!
2019-02-26T05:34:22.571155+00:00 app[web.1]: npm ERR! Failed at the zenform2@1.0.0 start script.
2019-02-26T05:34:22.571389+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-02-26T05:34:22.594258+00:00 app[web.1]: 
2019-02-26T05:34:22.603782+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-02-26T05:34:22.603786+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-02-26T05_34_22_573Z-debug.log
2019-02-26T05:34:22.294657+00:00 app[web.1]: 
2019-02-26T05:34:22.294678+00:00 app[web.1]: > zenform2@1.0.0 start /app
2019-02-26T05:34:22.294680+00:00 app[web.1]: > node ./bin/www
2019-02-26T05:34:22.294682+00:00 app[web.1]: 
2019-02-26T05:34:22.680467+00:00 heroku[web.1]: Process exited with status 1
2019-02-26T05:34:31.636059+00:00 heroku[web.1]: Starting process with command `npm start`
2019-02-26T05:34:33.484341+00:00 heroku[web.1]: State changed from starting to crashed
2019-02-26T05:34:33.458183+00:00 heroku[web.1]: Process exited with status 1
2019-02-26T05:34:33.279088+00:00 app[web.1]: 
2019-02-26T05:34:33.279111+00:00 app[web.1]: > zenform2@1.0.0 start /app
2019-02-26T05:34:33.279113+00:00 app[web.1]: > node ./bin/www
2019-02-26T05:34:33.279114+00:00 app[web.1]: 
2019-02-26T05:34:33.375778+00:00 app[web.1]: internal/modules/cjs/loader.js:583
2019-02-26T05:34:33.375782+00:00 app[web.1]: throw err;
2019-02-26T05:34:33.375784+00:00 app[web.1]: ^
2019-02-26T05:34:33.375785+00:00 app[web.1]: 
2019-02-26T05:34:33.375786+00:00 app[web.1]: Error: Cannot find module 'express'
2019-02-26T05:34:33.375788+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
2019-02-26T05:34:33.375794+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:507:25)
2019-02-26T05:34:33.375796+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-02-26T05:34:33.375797+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)
2019-02-26T05:34:33.375799+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:1:79)
2019-02-26T05:34:33.375800+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:689:30)
2019-02-26T05:34:33.375802+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
2019-02-26T05:34:33.375803+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:599:32)
2019-02-26T05:34:33.375805+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
2019-02-26T05:34:33.375807+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:530:3)
2019-02-26T05:34:33.384906+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-02-26T05:34:33.385464+00:00 app[web.1]: npm ERR! errno 1
2019-02-26T05:34:33.387225+00:00 app[web.1]: npm ERR! zenform2@1.0.0 start: `node ./bin/www`
2019-02-26T05:34:33.387461+00:00 app[web.1]: npm ERR! Exit status 1
2019-02-26T05:34:33.387805+00:00 app[web.1]: npm ERR!
2019-02-26T05:34:33.388040+00:00 app[web.1]: npm ERR! Failed at the zenform2@1.0.0 start script.
2019-02-26T05:34:33.388293+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-02-26T05:34:33.394659+00:00 app[web.1]: 
2019-02-26T05:34:33.394890+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-02-26T05:34:33.395027+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-02-26T05_34_33_390Z-debug.log
2019-02-26T05:34:34.796804+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.zenform.co request_id=e96f9d00-db65-4640-9468-1cf289bf46a2 fwd="76.102.21.229" dyno= connect= service= status=503 bytes= protocol=http
2019-02-26T05:36:09.766787+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.zenform.co request_id=7a163af9-f644-4e87-994f-b2b9ac38545c fwd="76.102.21.229" dyno= connect= service= status=503 bytes= protocol=http
 ▸    Log stream timed out. Please try again.

这是客户端文件夹中的我的package.json。

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:5000",
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "dependencies": {
    "@material-ui/core": "^3.4.0",
    "@material-ui/icons": "^3.0.1",
    "css-loader": "^1.0.1",
    "express": "^4.16.4",
    "jquery": "^3.3.1",
    "popper.js": "^1.14.4",
    "prop-types": "^15.6.2",
    "react": "^16.6.3",
    "react-dom": "^16.6.0",
    "react-ga": "^2.5.6",
    "react-helmet": "^5.2.0",
    "react-mailchimp-subscribe": "^2.0.2",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.1.1",
    "style-loader": "^0.23.1",
    "styled-components": "^4.1.2"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "nodemon": "^1.18.7"
  }
}

然后是主项目目录中的package.json。

{
  "name": "zenform2",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node ./bin/www",
    "heroku-postbuild": "cd client && npm install --only=dev && npm install && npm run build"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.18.3",
    "dotenv": "^6.2.0",
    "express": "^4.16.4",
    "request": "^2.88.0"
  }
}

如果有必要,以下是我的文件结构的图片。

enter image description here

知道我在做什么错吗?如果您需要更多信息,我很乐意回答任何问题。

0 个答案:

没有答案