tleunen / eslint-import-resolver-babel-module

Custom eslint resolve for babel-plugin-module-resolver
https://github.com/tleunen/babel-plugin-module-resolver
MIT License
248 stars 31 forks source link

'no-extraneous-dependencies' when alias name matches a dependency #46

Closed dlajarretie closed 6 years ago

dlajarretie commented 7 years ago

Having an alias with the same name as any dependency in node_modules will result in 'no-extraneous-dependencies'.

For instance I had an alias named "color" pointing to one of my own files, and it seems that one of the dependencies in my project requires a lib called "color". This throws 'no-extraneous-dependencies' : import { color } from 'color';

Now I understand it is intended that you can import anything from node_modules (even if not listed in package.json), and if you do eslint should tell you it's bad. But when bundling the app, the alias prevails over the extraneous dependency, so I think this plugin should behave accordingly and not return an error in that case.

Otherwise we should acknowledge that basically any npm package name becomes a reserved word for aliases.

tleunen commented 7 years ago

I will see if we can do anything about it, because I agree with you, everything can become a node module and we don't really want to break our builds because a word we used became a node dependency.

Maybe this is happening because eslint-plugin-import is run before this custom resolver for the no-extraneous-dependencies? @benmosher any insights?

benmosher commented 7 years ago

actually, I think if that rule is on it will report on any non-relative import (i.e. no leading ./ or ../) that isn't listed in the package.json.

I have a mental item for resolver spec version N+1 (3? I think) to allow resolvers to declare "core" modules to supersede this. ATM, though, there's no workaround short of defining any such alias as a core module in your .eslintrc.*: https://github.com/benmosher/eslint-plugin-import#importcore-modules