Javascript: import/no-unresolved raises false positives in many projects

Created on 5 Jun 2016  路  6Comments  路  Source: airbnb/javascript

I think import/no-unresolved isn't the kind of rule that belongs in a linting config, because it makes a lot of assumptions about how modules are resolved, leading to false positives in many common cases. For example in Webpack, the use of aliases or non-traditional but registered extensions such as .vue will raise a linting error when Webpack actually has no problems resolving these files.

Most helpful comment

There's a webpack resolver for eslint-plugin-import that handles things like extensions and aliases.

All 6 comments

The solution is to configure eslint-plugin-import with your custom resolution rules.

"What webpack does" is irrelevant - if you deviate from how the standard node require works, you're going to have to/want to configure _every_ tool you use - webpack and eslint are just two of many.

Hmm... this plugin is definitely the only other tool that I've had to configure - even on large projects with very demanding build processes. So it does seem strange to have to duplicate that config, especially because it comes with no advantages I can see. Webpack and other build tools _already_ provide very helpful module resolution errors (on save with a dev server) and _never_ trigger false positives. 馃槙

As someone who maintains a project generator for thousands of other developers, this is the only Airbnb rule I've had to disable completely - and it was in direct response to people opening issues about the confusing errors they get from ESLint when using Webpack aliases.

It seems clear this is a wontfix though, so I'll drop it.

@chrisvfritz You can try to file an issue on https://github.com/benmosher/eslint-plugin-import about it - it may be possible for them to configure it to read webpack's configuration automatically.

There's a webpack resolver for eslint-plugin-import that handles things like extensions and aliases.

@ljharb May be eslint-import-resolver-webpack should be mentioned in README.md ?

@alexicum i don't see the benefit; as I stated here, deviating from node's require algorithm is not something that should be encouraged, even tacitly.

Was this page helpful?
0 / 5 - 0 ratings