简体   繁体   中英

Eslint errorring importing jsx without extension

I am trying, in es6, to import jsx files without requiring the .jsx extension:

import LoginErrorDialog from './LoginErrorDialogView';

Not:

import LoginErrorDialog from './LoginErrorDialogView.jsx';

While I have got webpack to import in this fashion successfully:

export default {
  entry: './src/ui/js/app.js',
  output: {
    publicPath: '/',
    filename: 'bundle.js'
  },
  resolve: {
    extensions: ['.js', '.jsx'],

Eslint ( esw webpack.config.* ./ --color --ext .js --ext .jsx ) is still errorring.

Unable to resolve path to module './LoginView' import/no-unresolved

Any ideas?

I had the same issue here, and I fixed adding extra configuration in my .eslintrc .

In the extends property add:

"plugin:import/react"

In the settings property add:

"import/resolver": {
  "node": {
    "extensions": [".js",".jsx"]
   }
}

Your .eslintrc will look like:

{
    "extends": [
        ...
        "plugin:import/react",
        ...
    ],
   ...
    "settings": {
        "import/resolver": {
          "node": {
            "extensions": [".js",".jsx"]
          }
        }
    },
...
}

I resolved this issue by restarting my server. Simply run

npm start

添加到规则部分,在rule下方

"import/extensions": [0, { "js": "always" }]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM