无法加载 'package.json » eslint-config-react-app' 中声明的插件 'flowtype' 中的 npm 错误:找不到模块 'eslint/use-at-your-own-risk'
npm ERROR in Failed to load plugin 'flowtype' declared in 'package.json » eslint-config-react-app': Cannot find module 'eslint/use-at-your-own-risk'
我正在尝试在 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 包,但是 none 这些都有效。这可能是一个环境问题,因为我直接在 GShell 上部署,但我仍然不知道如何解决这个问题。我需要一些帮助。
我相信 Ryan link 编辑了一个适当的 Whosebug 线程,其中社区用户提供了一个很好的答案。我将其发布为访问此问题以找到解决方案的人的答案。
发生的事情是,当您 运行 npm start 时,它可能正在使用 eslint 进行一些检查。 create-react-app 有一些检查会在您遇到 eslint 错误时破坏您的构建,因此将它们关联起来是有道理的。
您在此处遇到的错误与 eslint 使用的称为 subpath exports 的节点功能有关,但它的支持取决于库的使用方式。这已被突出显示,例如在与 jest 一起使用时会导致问题。
对于 flowtype eslint 插件,this 是导致您出现问题的确切代码行。
您还可以阅读有关 typescript eslint plugin.
的类似问题报告
解决方案和原因,导致这个问题的原因是在 eslint-plugin-flowtype 的克隆中进行修复(假设原始插件缺乏维护)https://github.com/flow-typed/eslint-plugin-ft-flow/pull/23.
create-react-app 提出了一个问题,需要用新插件替换插件,这样可以进行更多维护并解决您遇到的问题。
问题 link 是 here。
我正在尝试在 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 包,但是 none 这些都有效。这可能是一个环境问题,因为我直接在 GShell 上部署,但我仍然不知道如何解决这个问题。我需要一些帮助。
我相信 Ryan link 编辑了一个适当的 Whosebug 线程,其中社区用户提供了一个很好的答案。我将其发布为访问此问题以找到解决方案的人的答案。
发生的事情是,当您 运行 npm start 时,它可能正在使用 eslint 进行一些检查。 create-react-app 有一些检查会在您遇到 eslint 错误时破坏您的构建,因此将它们关联起来是有道理的。
您在此处遇到的错误与 eslint 使用的称为 subpath exports 的节点功能有关,但它的支持取决于库的使用方式。这已被突出显示,例如在与 jest 一起使用时会导致问题。 对于 flowtype eslint 插件,this 是导致您出现问题的确切代码行。 您还可以阅读有关 typescript eslint plugin.
的类似问题报告解决方案和原因,导致这个问题的原因是在 eslint-plugin-flowtype 的克隆中进行修复(假设原始插件缺乏维护)https://github.com/flow-typed/eslint-plugin-ft-flow/pull/23.
create-react-app 提出了一个问题,需要用新插件替换插件,这样可以进行更多维护并解决您遇到的问题。 问题 link 是 here。