简体   繁体   English

没有扩展名的 Eslint 错误导入 jsx

[英]Eslint errorring importing jsx without extension

I am trying, in es6, to import jsx files without requiring the .jsx extension:我正在尝试在 es6 中导入 jsx 文件而不需要 .jsx 扩展名:

import LoginErrorDialog from './LoginErrorDialogView';

Not:不是:

import LoginErrorDialog from './LoginErrorDialogView.jsx';

While I have got webpack to import in this fashion successfully:虽然我已经成功地以这种方式导入了 webpack:

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. Eslint ( esw webpack.config.* ./ --color --ext .js --ext .jsx ) 仍然出错。

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 .我在这里遇到了同样的问题,我修复了在.eslintrc中添加额外的配置。

In the extends property add:extends属性中添加:

"plugin:import/react"

In the settings property add:settings属性中添加:

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

Your .eslintrc will look like:您的.eslintrc将如下所示:

{
    "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" }]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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