eslint-plugin-import: False positive of `no-import-module-exports` on `module` variable defined in the module
import 'something'; // => Cannot use import declarations in modules that export using CommonJS (module.exports = 'foo' or exports.bar = 'hi') import/no-import-module-exports
export const module = {};
module.foo = 42;
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 3
- Comments: 18 (10 by maintainers)
@ljharb I can reproduce it with the following code as per
eslint-plugin-import@2.26.0
:If I remove the
module.hot
condition there is no error, the following code is lint free.@snitin315 The solution for the
module.hot
issue with webpack’s [HotModuleReplacementPlugin](https://webpack.js.org/plugins/hot-module-replacement-plugin
) is to useimport.meta.webpackHot
.@snitin315 i definitely can reproduce the warnings, but they seem valid to me -
module
isn’t in scope in ES Modules. I’m not sure how to resolve this.right
unfortunately I can’t use
import
because the module system I’m using is CJS (due to"module": "commonjs"
entry on my tsconfig)What’s targeted shouldn’t matter, only the source;
module
isn’t available in ESM, and your source is ESM.My guess is that there’s a way webpack can use
import.meta
instead ofmodule
, and you’d both have less confusing code, and also bypass this overly-aggressive lint rule (that said, i’m still happy to remove some false positives)I figured out that I’m getting those lint errors when I access any property of
module
variable that was created by webpack.Here’s the code: https://gitlab.com/micalevisk/eslint-plugin-import-issue-2181
I might be missing something. I appreciate your help @ljharb
@micalevisk if you could set up a repro repo that would be most helpful.
I’m using it already 😕
this error arises when I use
eslint-config-airbnb-base@15.0.0
(eslint
v8.2.0), with v14 it worked. I didn’t investigate this further yet