Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jtbandes opened this issue Feb 25, 2021 · 2 comments
Closed

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

jtbandes opened this issue Feb 25, 2021 · 2 comments

Comments

@jtbandes
Copy link

jtbandes commented Feb 25, 2021

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

jtbandes added a commit to foxglove/studio that referenced this issue Feb 25, 2021
jtbandes added a commit to foxglove/studio that referenced this issue Feb 25, 2021
Restores eslint settings from the webviz project, along with some modifications for TypeScript compatibility and newer eslint/webpack versions. Contains a workaround for import-js/eslint-plugin-import#1996.
amacneil pushed a commit to foxglove/studio that referenced this issue Mar 8, 2021
Restores eslint settings from the webviz project, along with some modifications for TypeScript compatibility and newer eslint/webpack versions. Contains a workaround for import-js/eslint-plugin-import#1996.
amacneil pushed a commit to foxglove/studio that referenced this issue Mar 8, 2021
Restores eslint settings from the webviz project, along with some modifications for TypeScript compatibility and newer eslint/webpack versions. Contains a workaround for import-js/eslint-plugin-import#1996.
amacneil pushed a commit to foxglove/studio that referenced this issue Mar 8, 2021
Restores eslint settings from the webviz project, along with some modifications for TypeScript compatibility and newer eslint/webpack versions. Contains a workaround for import-js/eslint-plugin-import#1996.
amacneil pushed a commit to foxglove/studio that referenced this issue Mar 8, 2021
Restores eslint settings from the webviz project, along with some modifications for TypeScript compatibility and newer eslint/webpack versions. Contains a workaround for import-js/eslint-plugin-import#1996.
fregante added a commit to pixiebrix/pixiebrix-extension that referenced this issue Jun 16, 2021
fregante added a commit to pixiebrix/pixiebrix-extension that referenced this issue Jun 16, 2021
fregante added a commit to pixiebrix/pixiebrix-extension that referenced this issue Jun 16, 2021
@jvanderen1
Copy link

I am getting the same error when I have the following in my webpack config:

{
  ...,
  resolve: {
    ...,
    fallback: {
      https: false,
    }
  }
}

@ljharb
Copy link
Member

ljharb commented Nov 17, 2022

Fixed in #2598.

@ljharb ljharb closed this as completed Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants