import-js/eslint-plugin-import

Webpack config function executing multiple times when using `resolve.alias` and `eslint-import-resolver-webpack`

Open

#1,178 opened on Oct 8, 2018

View on GitHub
 (1 comment) (7 reactions) (1 assignee)JavaScript (1,540 forks)batch import
help wantedpackage: resolver/webpack

Repository metrics

Stars
 (4,946 stars)
PR merge metrics
 (Avg merge 138d 22h) (3 merged PRs in 30d)

Description

Description

If webpack.config.js represents config as a function with resolve.alias defined, and when we import/require this alias later in the code while using eslint-import-resolver-webpack for resolving imports in eslint, then webpack config function executing additionally multiple times: one time for each import with alias. I.e. it happens when .eslintrc.js uses eslint-config-airbnb-base and defines wepback import resolver as follows:

module.exports = {
  'extends': ['airbnb-base'],
  'settings': {
    'import/resolver': {
      'webpack': {
        'config': path.join(__dirname, 'webpack.config.js')
      }
    }
  }
};

How to reproduce

  1. Clone a test repo: https://github.com/andreyvolokitin/testcase1
  2. Run npm i && npm run build. The webpack build log in the console will contain multiple additional execute config strings, one for each usage of resolve.alias in src/js/index.js:
test
execute config
execute config
execute config
  1. Remove 'import/resolver' setting from .eslintrc.js and run npm run build again. The build log in console will contain only one instance of execute config:
test
execute config

Contributor guide