eslint-plugin-import: webpack resolver: config not used if config file requires transpilation

Hi everyone,

I get a lot of no-unresolved errors when using this with webpack 2.3.3.

Plugins:

"eslint-import-resolver-webpack": "^0.8.1",
"eslint-plugin-import": "^2.2.0",

Webpack resolve config:

resolve: {
  modules: [
    path.join(__dirname, 'src'),
    path.join(__dirname, 'styles'),
    'node_modules'
  ]
},,

Eslintrc:

"settings": {
  "import/resolver": {
    "webpack": {
      "config": "webpack.config-base.js"
    }
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 36
  • Comments: 20 (7 by maintainers)

Most upvoted comments

The problem right now is that the plugin is failing silently to parse the config. Solutions exist but it’s hard to find the cause in the first place : the only symptom is that eslint will not resolve imports.

The fix would be to document it properly or add a console warning when eslint is loading (don’t know if possible)

“+1s” aren’t helpful; please avoid cluttering up issues and instead, react with an emoji on the original post. I’ll now delete the +1s.

Some sort of warning or error seems reasonable; I’d be in favor of a hard failure when a config exists but fails to parse.

You can also transpile webpack config from es6 to es5 on the fly with babel-register

my package.json

"babel-preset-env": "^1.3.2",
"babel-register": "^6.26.0",
"eslint": "^4.10.0",
"eslint-import-resolver-webpack": "^0.8.3",
"eslint-plugin-import": "^2.8.0",

.eslintrc.json

"settings": {
  "import/resolver": {
    "webpack": {
      "config": "build/webpack.eslint.conf.js"
    }
  }
},

build/webpack.eslint.conf.js

require('babel-register')({
  presets: ['env'],
}); 

module.exports = require('./webpack.base.conf.js');

Same as @zhenyulin, my webpack config was not used at all. I replaced all my import/export with require/module.exports in my webpack.config.js and it’s now working

"settings": {
    "import/parser": "babel-eslint",
    "import/resolver": {
      "webpack": {
        "config": "./tools/webpack.config.js"
      }
    },

Mine doesn’t work earlier either, and I found out the issue to be I used ES6 syntax import and export in the webpack config file, which isn’t loaded by .eslintrc correctly, though babel-eslint has been applied as the parser. I resolved the issue by falling back to use require and module.exports.

HTH.

@bradennapier the only workaround is to disable these rules in eslint config until the issue will be resolved.