![](/img/trans.png)
[英]Module fails to parse at JSX, cannot find error in webpack, babel configs
[英]Babel ES-Lint parse errors in imported module. Cannot find module './parse-with-patch'
在過去的一個小時里,我一直在搜索 Github 和 Stack Overflow,但沒有關於如何使用 ES-Lint 解決此問題的答案。
.eslintrc.json
{
"parser": "babel-eslint",
"extends": ["airbnb", "prettier"],
"plugins": ["prettier", "flowtype"],
"rules": {
"prettier/prettier": ["error"],
"no-unused-expressions": 0,
"react/jsx-filename-extension": 0,
"class-methods-use-this": 0,
"default-case": 0,
"import/no-unresolved": 0,
"react/prefer-stateless-function": 0,
"import/no-named-as-default": 0
},
"parserOptions": {
"sourceType": "module",
"import/extensions": [".jsx", ".js"],
"allowImportExportEverywhere": true
}
}
開發依賴
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.1.0",
"babel-eslint": "^10.0.1",
"eslint": "^5.7.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-flowtype": "^2.34.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.1",
"flow-bin": "0.78.0",
"jest": "23.5.0",
"jest-react-native": "18.0.0",
"metro-react-native-babel-preset": "^0.45.0",
"prettier": "1.14.1",
"react-native-debugger-open": "0.3.17",
"react-test-renderer": "16.0.0-alpha.12",
"schedule": "0.4.0",
"semver": "5.5.0"
},
所有的 linter 選項都很好,但是如果我在整個應用程序中的每個導入語句都出現錯誤,我無法讓其他人使用這個配置。
有誰知道會發生什么?
只需禁用該規則即可解決此問題,即卸載 ESLint
“不幸的是,React + Redux 是最常見的場景。但是,還有很多其他情況 HOC 會迫使開發人員關閉此規則。”
https://github.com/benmosher/eslint-plugin-import/issues/544
https://github.com/reactjs/react-redux/issues/119
https://github.com/18F/calc/pull/1235
.eslintrc
"rules": {
"import/no-named-as-default": 0
}
這些步驟可能有效:
path
更改為path.ts
path
刪除node_modules
並重新安裝一切對我node_modules
:-(
babel-eslint
已被棄用。 更新到@babel/eslint-parser
。
https://tjaddison.com/blog/2021/03/updating-babel-eslint-to-babeleslint-parser-for-react-apps/
只需添加您的 eslint 規則。 對我來說很好
“解析器”:“關閉”,
全局卸載 EsLint 解決了我的問題: npm uninstall -g eslint
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.