import-js/eslint-plugin-import

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

Aperta

#1178 aperta il 8 ott 2018

 (1 commento) (7 reazioni) (1 assegnatario)JavaScript (1549 fork)batch import
help wantedpackage: resolver/webpack

Metriche repository

Star
 (5940 stelle)
Metriche merge PR
 (Merge medio 138g 22h) (3 PR mergiate in 30 g)

Descrizione

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

Guida contributor