Skip to content

webpack resolver crashes with { alias: { "some-module": false } } #1996

@jtbandes

Description

@jtbandes

eslint version: 7.20.0
eslint-plugin-import version: 2.22.1

According to the Webpack docs on resolve settings, a module can be ignored by providing a value of false. This is the replacement for the now-deprecated null-loader.

Setting resolve.alias to false will tell webpack to ignore a module.

module.exports = {
  //...
  resolve: {
    alias: {
      'ignored-module': false,
      './ignored-module': false,
    },
  },
};

But when this configuration is used, and import/namespace (or another rule from this plugin) tries to resolve the namespace, eslint crashes:

Oops! Something went wrong! :(

ESLint: 7.20.0

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type boolean (false)
    at Object.statSync (node:fs:1125:10)
    at Function.ExportMap.for (.../node_modules/eslint-plugin-import/src/ExportMap.js:305:20)
    at Function.get (.../node_modules/eslint-plugin-import/src/ExportMap.js:293:10)
    at forEach (.../node_modules/eslint-plugin-import/src/rules/namespace.js:49:35)
    at Array.forEach (<anonymous>)
    at Program (.../node_modules/eslint-plugin-import/src/rules/namespace.js:81:14)
    at .../node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (.../node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (.../node_modules/eslint/lib/linter/node-event-generator.js:256:26)

An example of when this would be used is when a module is imported only in dev mode, but is stubbed out for production builds. At runtime it will never be used, but the import still exists in the code so the linter tries to resolve it.

It might make sense to treat this the same way as externals:

https://github.com/benmosher/eslint-plugin-import/blob/f2db74a347a030c15a387826500cdc98203eac1e/resolvers/webpack/index.js#L142-L145

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions