How to remove ESlint error no-unresolved from importing 'react'

前端 未结 4 2153
春和景丽
春和景丽 2021-02-14 01:05

no-unresolved https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md

After installing eslint-import-resolver-webpack

相关标签:
4条回答
  • 2021-02-14 01:12

    Try installing eslint-import-resolver-webpack and adding this to your .eslintrc:

    "settings": {
      "import/resolver": "webpack"
    }
    
    0 讨论(0)
  • 2021-02-14 01:13

    Try

    resolve: {
        modules: [path.resolve(__dirname, 'public/src'), 'node_modules', path.resolve('node_modules')],
    }
    
    0 讨论(0)
  • 2021-02-14 01:16

    You can add an option to ignore case:

    "rules": {
       "import/no-unresolved": [
          2, 
          { "caseSensitive": false }
       ]
    }
    

    This thread at github also describes how the linter was checking case for parts of the path which come before the folder containing package.json. If you for example have the path: C:/Workspace/app and you navigate to it using cd C:/workspace/app (lowercase workspace), the linter would also give an error on the imports. Looks like it should now be fixed, but perhaps you are still using an older version.

    0 讨论(0)
  • 2021-02-14 01:24

    The problem is that your webpack config is written in ES6 format, which doesn't play well with eslint-import-resolver-webpack.

    So, you either refactor your webpack.config.js using ES5 syntax, or you get rid of eslint-import-resolver-webpack.

    See here for the full solution: eslint plugin docs

    0 讨论(0)
提交回复
热议问题