eslint-plugin-jest icon indicating copy to clipboard operation
eslint-plugin-jest copied to clipboard

`__dirname is not defined in ES module scope`

Open seahindeniz opened this issue 7 months ago • 1 comments

Hello, I'm getting __dirname not defined error when I use the plugin in an ESM ("type": "module") project and I believe this line is the source: https://github.com/jest-community/eslint-plugin-jest/blob/33c5efef26a4c2d4f8a52d56720a954cc06f1f8d/src/index.ts#L23

I have seen from the node_modules directory that there's only CJS files and no ESM module. If there's no technical blocker, bundling and exposing ESM modules would be great.

Just to keep this in mind, the following declaration in package.json is needed

    "exports": {
        ".": {
            "types": "./dist/index.d.ts",
            "import": "./dist/index.js", // for esm
            "require": "./dist/index.cjs" // for cjs
        },
    },

seahindeniz avatar May 05 '25 07:05 seahindeniz

Given the nature of this package, I don't think there's much value in including two versions of the code in the published package though I don't mind potentially changing such lines to something more robust.

In saying that, I can't reproduce this - importing the plugin in a project with type: module in the package.json works fine; could you provide more details on your setup?

G-Rath avatar May 09 '25 21:05 G-Rath

Yeah, we don't list module in our package.json, so js files should be treated as CJS. How are you importing?

SimenB avatar Jul 02 '25 07:07 SimenB