【问题标题】:Heroku app crashed because of eslint faulty importHeroku 应用程序因 eslint 错误导入而崩溃
【发布时间】:2018-05-22 20:41:34
【问题描述】:

我正在开发一个应用程序,它使用 VueJS 显示视图并使用 ExpressJS 作为服务器。

目前在本地运行良好,但在 Heroku 上成功部署后,它不会加载应用程序并使测功机崩溃。

我的文件夹结构是这样的:

  • 项目根目录
    • 客户端
      • 客户端的package.json
    • 服务器
      • 服务器的package.json
    • package.json 告诉 Heroku 在两个文件夹中安装依赖项

这是 Heroku 用来构建整个应用程序的 package.json:

{
    "name": "my-app",
    "version": "0.1.0",
    "scripts": {
        "postinstall": "npm install --prefix server && npm install --prefix client"
    }
}

服务器的package.json:

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "./src/app.js",
  "scripts": {
      "start": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
  "lint": "./node_modules/.bin/eslint **/*.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
  "body-parser": "^1.18.2",
  "cors": "^2.8.4",
  "eslint": "^4.12.1",
  "express": "^4.16.2",
  "morgan": "^1.9.0",
  "nodemon": "^1.12.5",
  "pg": "^7.4.0",
  "sequelize": "^4.27.0"
},
"devDependencies": {
    "eslint-config-standard": "^10.2.1",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-node": "^5.2.1",
    "eslint-plugin-promise": "^3.6.0",
    "eslint-plugin-standard": "^3.0.1"
}
}

我检查了日志,问题出在 eslint 库中,Heroku 在我的项目中找不到该库。关于如何解决这个问题的任何想法?

2017-12-08T14:55:35.408127+00:00 app[web.1]: Cannot find module 'eslint-config-standard'
2017-12-08T14:55:35.408145+00:00 app[web.1]: Referenced from: /app/server/.eslintrc.js
2017-12-08T14:55:35.408945+00:00 app[web.1]: Error: Cannot find module 'eslint-config-standard'
2017-12-08T14:55:35.408947+00:00 app[web.1]: Referenced from: /app/server/.eslintrc.js
2017-12-08T14:55:35.408948+00:00 app[web.1]:     at ModuleResolver.resolve (/app/server/node_modules/eslint/lib/util/module-resolver.js:74:19)
2017-12-08T14:55:35.408949+00:00 app[web.1]:     at resolve (/app/server/node_modules/eslint/lib/config/config-file.js:471:25)
2017-12-08T14:55:35.408950+00:00 app[web.1]:     at load (/app/server/node_modules/eslint/lib/config/config-file.js:542:26)
2017-12-08T14:55:35.408951+00:00 app[web.1]:     at configExtends.reduceRight (/app/server/node_modules/eslint/lib/config/config-file.js:421:36)
2017-12-08T14:55:35.408951+00:00 app[web.1]:     at Array.reduceRight (<anonymous>)
2017-12-08T14:55:35.408952+00:00 app[web.1]:     at applyExtends (/app/server/node_modules/eslint/lib/config/config-file.js:403:28)
2017-12-08T14:55:35.408953+00:00 app[web.1]:     at loadFromDisk (/app/server/node_modules/eslint/lib/config/config-file.js:514:22)
2017-12-08T14:55:35.408953+00:00 app[web.1]:     at Object.load (/app/server/node_modules/eslint/lib/config/config-file.js:550:20)
2017-12-08T14:55:35.408954+00:00 app[web.1]:     at Config.getLocalConfigHierarchy (/app/server/node_modules/eslint/lib/config.js:228:44)
2017-12-08T14:55:35.408955+00:00 app[web.1]:     at Config.getConfigHierarchy (/app/server/node_modules/eslint/lib/config.js:180:43)
2017-12-08T14:55:35.464317+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-12-08T14:55:35.464681+00:00 app[web.1]: npm ERR! errno 1
2017-12-08T14:55:35.466080+00:00 app[web.1]: npm ERR! server@1.0.0 lint: `eslint **/*.js`
2017-12-08T14:55:35.466205+00:00 app[web.1]: npm ERR! Exit status 1
2017-12-08T14:55:35.466413+00:00 app[web.1]: npm ERR! 
2017-12-08T14:55:35.466555+00:00 app[web.1]: npm ERR! Failed at the server@1.0.0 lint script.
2017-12-08T14:55:35.466726+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-12-08T14:55:35.491352+00:00 app[web.1]: 
2017-12-08T14:55:35.491535+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-12-08T14:55:35.491648+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2017-12-08T14_55_35_468Z-debug.log
2017-12-08T14:55:35.506231+00:00 app[web.1]: [nodemon] app crashed - waiting for file changes before starting...
2017-12-08T14:56:08.700333+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/status" host=babbelbord.herokuapp.com request_id=f86a8552-14b5-477c-b79d-d575ad30bffa fwd="84.81.81.130" dyno= connect= service= status=503 bytes= protocol=https

【问题讨论】:

    标签: express heroku npm eslint package.json


    【解决方案1】:

    您似乎从 /app/server/.eslintrc.js 中引用了 eslint-config-standard,但是您的 package.json 没有任何依赖项。

    您将需要运行npm install eslint-config-standard --save,它将在您的 package.json 中创建一个依赖项。然后你应该保存以提交更改并再次部署到 heroku。

    因为你没有在 package.json 中声明你的依赖,你的 dyno 不会知道安装它。我怀疑您只是忘记将--save 标志添加到您原来的npm install 上,因此它只安装到您的node_modules 文件夹中,而没有在package.json 中输入。

    【讨论】:

    • 感谢您帮助艾略特。但是,我检查了一下,我已经在 devDependencies 中有那个包。如果可以帮助您,我会使用服务器 package.json 文件更新问题
    • 你能提供/app/server/.eslintrc.js的代码吗?这真的很有帮助,因为它是产生错误的代码。
    • 了解您的 procfile 正在调用的命令也很有用 :)
    • 这是.eslintrc.js文件内容:module.exports = { "extends": "standard" };
    • 这是 Procfile 的内容: web: npm start --prefix server
    【解决方案2】:

    感谢 Heroku 的支持,找到了答案。问题是我的依赖项是在 package.json 文件的 devDependencies 中定义的,而它们应该在 dependencies 中声明以便 Heroku 正常工作。

    【讨论】:

      猜你喜欢
      • 2020-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-11
      • 2013-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多