eslint-import-resolver-webpack reserved alias of `base`?
See original GitHub issueHere’s a weird one: If a webpack alias is named base
it is ignored by eslint-import-resolver-webpack
.
With the following configs:
// webpack.shared.config.js
// ...
resolve: {
alias: {
base: path.resolve(__dirname, PATH_SOURCE, '_patterns/00-base/'), // <-- see `base` here
atoms: path.resolve(__dirname, PATH_SOURCE, '_patterns/01-atoms/'),
molecules: path.resolve(__dirname, PATH_SOURCE, '_patterns/02-molecules/'),
organisms: path.resolve(__dirname, PATH_SOURCE, '_patterns/03-organisms/'),
templates: path.resolve(__dirname, PATH_SOURCE, '_patterns/04-templates/'),
pages: path.resolve(__dirname, PATH_SOURCE, '_patterns/05-pages/'),
},
},
// .eslintrc.js
// ...
settings: {
'import/resolver': {
webpack: {
config: 'webpack.shared.config.js',
}
}
}
And then implementations all around my code like:
// design-system.js
// ...
import * as base from 'base';
import * as alert from 'atoms/alert';
import * as card from 'molecules/card';
import * as article from 'organisms/article';
Will result in this eslint error for only base:
9:1 error 'base' should be listed in the project's dependencies. Run 'npm i -S base' to add it import/no-extraneous-dependencies
However, if I change all instances of base
to derp
, then we’re gold:
// webpack.shared.config.js
// ...
resolve: {
alias: {
derp: path.resolve(__dirname, PATH_SOURCE, '_patterns/00-base/'), // <-- see `derp` here
atoms: path.resolve(__dirname, PATH_SOURCE, '_patterns/01-atoms/'),
molecules: path.resolve(__dirname, PATH_SOURCE, '_patterns/02-molecules/'),
organisms: path.resolve(__dirname, PATH_SOURCE, '_patterns/03-organisms/'),
templates: path.resolve(__dirname, PATH_SOURCE, '_patterns/04-templates/'),
pages: path.resolve(__dirname, PATH_SOURCE, '_patterns/05-pages/'),
},
},
// design-system.js
// ...
import * as derp from 'derp';
import * as alert from 'atoms/alert';
import * as card from 'molecules/card';
import * as article from 'organisms/article';
The above config works flawlessly with no eslint errors. So, TLDR:
Is base
as reserved word to eslint?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
eslint-import-resolver-webpack - npm
Resolve paths to dependencies, given a webpack.config.js. Plugin for eslint-plugin-import.. Latest version: 0.13.2, last published: a year ...
Read more >Local imports using webpack aliases are being incorrectly ...
I'm having a different issue, but I think they are related. In my case, I have some aliases set in webpack, and resolver...
Read more >eslint error showing with webpack alias - Stack Overflow
I have installed eslint-import-resolver-webpack plugin and put below code into .eslintrc.js or .eslintrc file :
Read more >Configuring aliases in webpack + VS Code + Typescript + Jest
Webpack needs to know physical paths that map to the aliases we want to create. In order to inform that mapping, we need...
Read more >eslint-import-resolver-alias
Your eslint config isn't using a webpack resolver, so your webpack config doesn't come into play. In this case, the issue is that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ljharb WINS ^^
(Typically webpack aliases are best when they can’t possibly be real package names)