node.js - 无法加载在 'flowtype' : Cannot find module 'package.json » eslint-config-react-app' 中声明的插件 'eslint/use-at-your-own-risk' 中的 npm 错误

标签 node.js reactjs google-app-engine npm google-cloud-platform

我正在尝试在 GCP 上部署我的 React 应用程序。所以在 Gcloud shell 中,我克隆了我的 React 项目并输入了

npm install
npm run build

但是,我得到了这个错误:

ERROR in Failed to load plugin 'flowtype' declared in 'package.json » eslint-config-react-app': Cannot find module 'eslint/use-at-your-own-risk'
Require stack:
- /home/oizfwvlh/Portfolio/portfolio/node_modules/eslint-plugin-flowtype/dist/utilities/getBuiltinRule.js
- /home/oizfwvlh/Portfolio/portfolio/node_modules/eslint-plugin-flowtype/dist/rules/noUnusedExpressions.js
- /home/oizfwvlh/Portfolio/portfolio/node_modules/eslint-plugin-flowtype/dist/index.js
- /home/oizfwvlh/Portfolio/portfolio/node_modules/@eslint/eslintrc/dist/eslintrc.cjs

我不知道为什么。当我在我的电脑上测试时,我根本没有遇到这个问题。这是我的 package.json:

{
  "name": "portfolio",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.7.1",
    "@emotion/styled": "^11.6.0",
    "@material-ui/core": "^4.12.3",
    "@material-ui/icons": "^4.11.2",
    "@mui/icons-material": "^5.2.5",
    "@mui/material": "^5.2.5",
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@testing-library/user-event": "^13.5.0",
    "bootstrap": "^5.1.3",
    "chart.js": "^3.7.0",
    "chartjs-plugin-deferred": "^1.0.2",
    "emailjs-com": "^3.2.0",
    "jquery": "^3.6.0",
    "node-sass": "^7.0.0",
    "popper.js": "^1.16.1",
    "react": "^17.0.2",
    "react-bootstrap": "^2.1.0",
    "react-chartjs-2": "^4.0.0",
    "react-dom": "^17.0.2",
    "react-router-dom": "^6.2.1",
    "react-scripts": "5.0.0",
    "react-vertical-timeline-component": "^3.5.2",
    "web-vitals": "^2.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

我尝试在本地和全局安装 eslint 包,但这些都不起作用。这可能是一个环境问题,因为我直接在 GShell 上部署,但我仍然不知道如何解决这个问题。我需要一些帮助。

最佳答案

我相信 Ryan 已经链接了一个适当的 stackoverflow 线程,其中社区用户提供了一个很好的答案。我将其发布为访问此问题以找到解决方案的任何人的答案。

发生的事情是,当您运行 npm start 时,它可能正在使用 eslint 进行一些检查。如果您有 eslint 错误,create-react-app 会进行一些检查来破坏您的构建,因此将它们关联起来是有道理的。

您在此处遇到的错误与 eslint 使用的称为 subpath exports 的 Node 功能有关。但它的支持取决于库的使用方式。这已被突出显示,例如在与 jest 一起使用时会导致问题。 对于 flowtype eslint 插件 this是导致您出现问题的确切代码行。 您还可以阅读关于 typescript eslint plugin 报告的类似问题。 .


解决方案和原因,导致此问题的原因是要在 eslint-plugin-flowtype 的克隆中进行修复(假设原始插件缺乏维护)这里 https://github.com/flow-typed/eslint-plugin-ft-flow/pull/23 .

create-react-app 提出了一个问题,将插件替换为新插件,这将有更多维护并解决您遇到的问题。 问题链接是here .

关于node.js - 无法加载在 'flowtype' : Cannot find module 'package.json » eslint-config-react-app' 中声明的插件 'eslint/use-at-your-own-risk' 中的 npm 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70573722/

相关文章:

javascript - promise 所有并获得请求

javascript - 导航回来时 react native 重新运行功能

google-app-engine - 每次使用 App Engine 中的数据存储都会超时

google-app-engine - 我可以在 Google Cloud End Point 中返回一个泛型吗

google-app-engine - 如何计算存储在 Google Appengine 数据存储区中的给定类型的所有条目数?

node.js - 如何将对象从 Sequelize 传递到 Handlebars 部分?

javascript - 怎么能逼 Jade 留 mustache ?

node.js - 不支持查询关键条件: Already have a Hash and a Range Key

javascript - 使用 javascript map() 时如何跳过某些元素

reactjs - React - 如何使用常规 for 循环呈现多个按钮?