eslint-plugin-tree-shaking icon indicating copy to clipboard operation
eslint-plugin-tree-shaking copied to clipboard

error Could not find module scope. after upgrade to eslint 9.16.0

Open gergm opened this issue 1 year ago • 3 comments

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',
          ],
        },
      ],
    },
  ],

`

gergm avatar Dec 09 '24 22:12 gergm

As a temporary solution, using https://eslint.org/blog/2024/05/eslint-compatibility-utilities/#using-the-compatibility-utilities works as expected.

matzeeable avatar Jan 08 '25 14:01 matzeeable

Thanks @matzeeable. I believe that I have followed that guide, ie, I have:

  1. Installed @eslint/compat as a dev dependency
  2. 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?

gergm avatar Jan 14 '25 03:01 gergm

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.

tbartley avatar Feb 25 '25 01:02 tbartley