Babel ES-Lint解析导入模块中的错误。找不到模块'./parse-with-patch'

时间:2018-10-19 14:36:59

标签: javascript reactjs babel eslint

在过去的一个小时中,我一直在搜索Github和Stack Overflow,但没有关于如何使用ES-Lint解决此问题的答案。

enter image description here

.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

"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选项都可以正常运行,这很棒,但是如果我在整个应用程序中的每个导入语句中都遇到错误,则无法让其他人使用此配置。

有人知道会发生什么吗?

4 个答案:

答案 0 :(得分:1)

全局卸载EsLint解决了我的问题:     npm uninstall -g eslint

答案 1 :(得分:1)

只需禁用该规则即可解决卸载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
}

答案 2 :(得分:1)

这些步骤可能有效:

  1. path 改为 path.ts
  2. 保存
  3. 再次将其更改为 path
  4. 保存

答案 3 :(得分:0)

删除node_modules并重新安装对我有用的所有方法:-(

相关问题