Heroku构建成功,但是应用程序错误

时间:2018-08-18 03:27:08

标签: node.js reactjs heroku deployment

我正在尝试部署一个具有节点后端和React前端的应用程序。我正在使用heroku,下面是我的代码。它说mongo存在错误,我尝试重新安装节点模块。我对heroku没有太多经验,所以任何投入都很棒。提前致谢。 在server.js中-

if (process.env.NODE_ENV === "production") {
  app.use(express.static("client/build"));

  app.get("*", (req, res) => {
    res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
  });
}

在package.json中-

{
  "author": "Spotify",
  "name": "web-api-auth-examples",
  "description": "Basic examples of the Spotify authorization flows through OAuth 2",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "client": "npm start --prefix client",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "version": "0.0.2",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.18.3",
    "cors": "^2.8.4",
    "dateformat": "^3.0.3",
    "express": "~4.16.0",
    "jsonwebtoken": "^8.3.0",
    "multer": "^1.3.1",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "querystring": "~0.2.0",
    "request": "~2.83.0",
    "request-promise": "^4.2.2",
    "validator": "^10.4.0"
  }
}

heroku日志-

2018-08-18T03:08:30.415893+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-08-18T03:08:30.415896+00:00 app[web.1]: npm ERR! errno 1
2018-08-18T03:08:30.415899+00:00 app[web.1]: npm ERR! web-api-auth-examples@0.0.2 start: `node server.js                    `
2018-08-18T03:08:30.415909+00:00 app[web.1]: npm ERR! Failed at the web-api-auth-examples@0.0.2 start sc                    ript.
2018-08-18T03:08:30.415905+00:00 app[web.1]: npm ERR!
2018-08-18T03:08:30.423862+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-08-18T03:08:30.423859+00:00 app[web.1]:
2018-08-18T03:08:30.415901+00:00 app[web.1]: npm ERR! Exit status 1
2018-08-18T03:08:30.415913+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is                     likely additional logging output above.
2018-08-18T03:08:30.423864+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-08-18T03_08_30_416Z-debug                    .log
2018-08-18T03:08:30.536987+00:00 heroku[web.1]: State changed from starting to crashed
2018-08-18T03:08:30.539851+00:00 heroku[web.1]: State changed from crashed to starting
2018-08-18T03:08:30.502667+00:00 heroku[web.1]: Process exited with status 1
2018-08-18T03:08:42.074442+00:00 heroku[web.1]: Starting process with command `npm start`
2018-08-18T03:08:45.349152+00:00 app[web.1]:
2018-08-18T03:08:45.349173+00:00 app[web.1]: > node server.js
2018-08-18T03:08:45.349171+00:00 app[web.1]: > web-api-auth-examples@0.0.2 start /app
2018-08-18T03:08:45.349174+00:00 app[web.1]:
2018-08-18T03:08:46.080144+00:00 app[web.1]: module.js:549
2018-08-18T03:08:46.080165+00:00 app[web.1]: throw err;
2018-08-18T03:08:46.080167+00:00 app[web.1]: ^
2018-08-18T03:08:46.080168+00:00 app[web.1]:
2018-08-18T03:08:46.080171+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2018-08-18T03:08:46.080172+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:547:15)
2018-08-18T03:08:46.080174+00:00 app[web.1]: at Function.Module._load (module.js:474:25)

1 个答案:

答案 0 :(得分:1)

我从您的错误和给定的package.json中了解到,您在应用程序中的某处使用了猫鼬,但实际上未安装猫鼬。

安装猫鼬来解决该问题

npm install -s mongoose
相关问题