question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

eslint-import-resolver-webpack reserved alias of `base`?

See original GitHub issue

Here’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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
illepiccommented, Dec 27, 2017
2017-12-27 at 11 03

@ljharb WINS ^^

1reaction
ljharbcommented, Dec 27, 2017

(Typically webpack aliases are best when they can’t possibly be real package names)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found