Heroku部署失败:无法加载在"package.json"中声明的插件"cypress":找不到模块"eslint-plugin-cypress" [英] Heroku deployment failing: Failed to load plugin 'cypress' declared in 'package.json': Cannot find module 'eslint-plugin-cypress'

查看:197
本文介绍了Heroku部署失败:无法加载在"package.json"中声明的插件"cypress":找不到模块"eslint-plugin-cypress"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过更多研究后更新#2

更多地查看构建日志,看起来赛普拉斯是通过安装后钩子安装的,该钩子会下载由于某种原因Heroku在构建过程中未拾取的二进制文件,除非将配置设置为 NPM_CONFIG_PRODUCTION = false.将失败的构建日志成功的构建日志,此安装后挂钩无法运行:

 >cypress@6.0.0安装后/tmp/build_0453cc7d/frontend/node_modules/cypress 

为什么在 npm run build 之前未安装此软件包以及潜在的其他 devDependencies ,但似乎与Heroku的文档(devDependencies 是默认安装的.

使用更多构建信息更新#1

这里有一个要点,显示失败的构建日志和成功的构建日志(在使用 heroku config:set NPM_CONFIG_PRODUCTION = false 配置Heroku不修剪 devDependencies 后)./p>

https://gist.github.com/ddehart/9e0ca72a3f20f104e05d70eed6de6c64

修剪似乎是在构建过程中安装了赛普拉斯之后启动的,因此尽管Heroku的文档说:

,但不清楚为什么设置 NPM_CONFIG_PRODUCTION = false 会提示赛普拉斯安装

默认情况下,Heroku将安装 package.json dependencies devDependencies 下列出的所有依赖项.

原始问题

在部署到Heroku时出现 npm run build 错误:

无法加载在"package.json"中声明的插件"cypress":找不到模块"eslint-plugin-cypress"

这是我的 package.json 供参考:

 <代码> {"name":"frontend",版本":"0.1.0&",私人":是的,依赖项":{"@ testing-library/jest-dom":"^ 5.11.6","@ testing-library/react":"^ 11.2.2","@ testing-library/user-event":"^ 12.2.2","react":"^ 17.0.1","react-dom":"^ 17.0.1",反应脚本":"^ 4.0.1";},脚本":{"start":"react-scripts start","build":"react-scripts build","test":"react-scripts test",弹出":反应脚本弹出","cypress:open":"cypress open","cypress:run":"cypress run";},"eslintConfig":{扩展":["react-app",插件:柏树/推荐";]},浏览器列表":{生产":[> 0.2%",未死",不是op_mini全部";],发展":[最后1个镀铬版本",最新的1个Firefox版本",最后1个野生动物园版本"]},"devDependencies":{"@ testing-library/cypress":"^ 7.0.2","cypress":"^ 6.0.0&","eslint-plugin-cypress":"^ 2.11.2";}} 

该项目是使用Create React App启动的. npm run build 成功在本地完成,没有任何问题,所以我首先想到Heroku正在修剪 devDependencies ,但是回顾其他成功的构建日志,则表明修剪在成功构建后发生

如果有帮助,这是我上次成功构建的 package.json .

 <代码> {"name":"frontend",版本":"0.1.0&",私人":是的,依赖项":{"@ testing-library/jest-dom":"^ 4.2.4"," @ testing-library/react":"^ 9.5.0&","@ testing-library/user-event":"^ 7.2.1","react":"^ 16.14.0&","react-dom":"^ 16.14.0&",反应脚本":"3.4.3";},脚本":{"start":"react-scripts start","build":"react-scripts build","test":"react-scripts test",弹出":反应脚本弹出","cypress:open":"cypress open"},"eslintConfig":{扩展":["react-app",插件:柏树/推荐";]},浏览器列表":{生产":[> 0.2%",未死",不是op_mini全部";],发展":[最后1个镀铬版本",最新的1个Firefox版本",最后1个野生动物园版本"]},"devDependencies":{"cypress":"^ 5.4.0&","eslint-plugin-cypress":"^ 2.11.2";}} 

认为,尽管自上次成功构建以来,这并没有改变,但该构建仍在抱怨这一点.

 "eslintConfig":{扩展":["react-app",插件:柏树/推荐";]}, 

删除该插件声明当然会在我的IDE中破坏Cypress.有什么方法可以解决构建错误或对Heroku实例本身进行故障排除吗?

解决方案

我没有设置 NPM_CONFIG_PRODUCTION = false ,而是最终将Cypress eslintConfig 移到了自己的 cypress 目录中的> .eslintrc.json 文件.由于Heroku似乎只是挂在主 package.json 中引用的Cypress插件上,因此完全删除该配置可解决Heroku构建问题,而不会影响我的IDE,而不必依赖于非标准的 NPM_CONFIG_PRODUCTION 设置.

每个赛普拉斯的文档 .eslintrc.json 文件只需要使用此规则即可:

 <代码> {扩展":[插件:柏树/推荐";]} 

Update #2 after some more research

Looking into the build logs some more, it looks like Cypress gets installed via a postinstall hook that downloads a binary that Heroku doesn't pick up in the build process for some reason unless config is set to NPM_CONFIG_PRODUCTION=false. Comparing the failed build log with the successful build log, this postinstall hook doesn't run:

> cypress@6.0.0 postinstall /tmp/build_0453cc7d/frontend/node_modules/cypress

Why this and potentially other devDependencies don't get installed prior to npm run build doesn't appear to be documented and runs contrary to Heroku's documentation that devDependencies are installed by default.

Update #1 with more build info

Here's a gist that shows the failing build log and the succeeding build log (after configuring Heroku not to prune devDependencies using heroku config:set NPM_CONFIG_PRODUCTION=false).

https://gist.github.com/ddehart/9e0ca72a3f20f104e05d70eed6de6c64

The pruning appears to be initiated after the build process installed Cypress, so it's not clear why setting NPM_CONFIG_PRODUCTION=false prompted the Cypress installation, despite Heroku's documentation that says:

By default, Heroku will install all dependencies listed in package.json under dependencies and devDependencies.

Original question

I'm getting this npm run build error when deploying to Heroku:

Failed to load plugin 'cypress' declared in 'package.json': Cannot find module 'eslint-plugin-cypress'

Here's my package.json for reference:

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.2.2",
    "@testing-library/user-event": "^12.2.2",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "^4.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "cypress:open": "cypress open",
    "cypress:run": "cypress run"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "plugin:cypress/recommended"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@testing-library/cypress": "^7.0.2",
    "cypress": "^6.0.0",
    "eslint-plugin-cypress": "^2.11.2"
  }
}

The project was initiated using Create React App. npm run build succeeds without any issues locally, so I first thought maybe Heroku was pruning devDependencies, but looking back at other build logs that succeeded show that pruning happens after a successful build.

If it helps, here's my package.json from the last successful build.

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.14.0",
    "react-dom": "^16.14.0",
    "react-scripts": "3.4.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "cypress:open": "cypress open"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "plugin:cypress/recommended"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "cypress": "^5.4.0",
    "eslint-plugin-cypress": "^2.11.2"
  }
}

I think the build is complaining about this, although that hasn't changed at all from the last successful build.

  "eslintConfig": {
    "extends": [
      "react-app",
      "plugin:cypress/recommended"
    ]
  },

Removing that plugin declaration of course ruins Cypress in my IDE. Is there any way to work around the build error or troubleshoot on the Heroku instance itself?

解决方案

Rather than setting NPM_CONFIG_PRODUCTION=false, I ended up moving the Cypress eslintConfig into its own .eslintrc.json file within the cypress directory. Since Heroku only seems to be getting hung up on the Cypress plugin referenced in the main package.json, removing that configuration altogether fixed the Heroku build issue without affecting my IDE and without having to rely on the non-standard NPM_CONFIG_PRODUCTION setting.

Per Cypress's documentation, the .eslintrc.json file just needs this for the recommended rules:

{
  "extends": [
    "plugin:cypress/recommended"
  ]
}

这篇关于Heroku部署失败:无法加载在"package.json"中声明的插件"cypress":找不到模块"eslint-plugin-cypress"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆