eslint-plugin-tree-shaking
eslint-plugin-tree-shaking copied to clipboard
error Could not find module scope. after upgrade to eslint 9.16.0
My project is using eslint-plugin-tree-shaking 1.12.2 and after upgrading from eslint 8.57.1 to eslint 9.16.0, I am getting this error reported for several of my source files:
7:1 error Could not find module scope. If you are using the latest version of this plugin, please consider filing an issue noting this message, the offending statement, your ESLint version, and any active ESLint presets and plugins tree-shaking/no-side-effects-in-initialization
Note that line 7 is the first import line of the file.
Here are relevant excerpts from eslint.config.mjs:
` import treeShaking from 'eslint-plugin-tree-shaking'
plugins: {
'@typescript-eslint': typescriptEslint,
import: fixupPluginRules(_import),
prettier,
'tree-shaking': fixupPluginRules(treeShaking),
},
'tree-shaking/no-side-effects-in-initialization': [
2,
{
noSideEffectsWhenCalled: [
{
module: 'io-ts',
functions: [
'array',
'literal',
'partial',
'record',
'type',
'union',
'Type',
],
},
],
},
],
`
As a temporary solution, using https://eslint.org/blog/2024/05/eslint-compatibility-utilities/#using-the-compatibility-utilities works as expected.
Thanks @matzeeable. I believe that I have followed that guide, ie, I have:
- Installed @eslint/compat as a dev dependency
- Added fixupPluginRules to my eslint.config.mjs file
Here are the relevant snippets from my eslint.config.mjs file:
import treeShaking from 'eslint-plugin-tree-shaking'
import { fixupPluginRules } from '@eslint/compat'
export default [
{
plugins: {
'tree-shaking': fixupPluginRules(treeShaking),
},
rules: {
'tree-shaking/no-side-effects-in-initialization': 2,
},
},
]
then when I run yarn eslint "{bin,integration-tests,src}/**/*.{ts,tsx}"
I get error Could not find module scope.
What am I missing?
I hit the same issue. I had the following in my eslint config:
languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: 'script',
parserOptions: {
project: './tsconfig.json',
},
},
Removing ecmaVersion and sourceType resolved it for me. I didn't try and deduce which one in particular resolved it but I presume it was the ecmaVersion.