Heroku 应用程序因 eslint 错误导入而崩溃
Heroku app crashed because of eslint faulty import
我正在开发一个应用程序,它使用 VueJS 来显示视图并使用 ExpressJS 作为服务器。
到目前为止在本地工作正常,但在 Heroku 上成功部署后,它不会加载应用程序并导致 dyno 崩溃。
我的文件夹结构是这样的:
- 项目根目录
- 客户
- 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
您似乎在 /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
中输入。
感谢 Heroku 的支持,找到了答案。问题是我的依赖项是在 package.json 文件的 devDependencies
中定义的,而它们应该在 dependencies
中声明以使 Heroku 正常工作。
我正在开发一个应用程序,它使用 VueJS 来显示视图并使用 ExpressJS 作为服务器。
到目前为止在本地工作正常,但在 Heroku 上成功部署后,它不会加载应用程序并导致 dyno 崩溃。
我的文件夹结构是这样的:
- 项目根目录
- 客户
- 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
您似乎在 /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
中输入。
感谢 Heroku 的支持,找到了答案。问题是我的依赖项是在 package.json 文件的 devDependencies
中定义的,而它们应该在 dependencies
中声明以使 Heroku 正常工作。