taskworld / eslint-plugin-local

module.exports = require('../../.eslintplugin')
MIT License
35 stars 8 forks source link

Doesn't seem work with type `"module"` in package.json #3

Closed jespertheend closed 6 months ago

jespertheend commented 2 years ago

I can't seem to get this to work without removing "type": "module" from my package.json.

Either I place the file .eslintplugin.js in my root and I get:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/Jesper/game-engine/.eslintplugin.js from /Users/Jesper/game-engine/node_modules/eslint-plugin-local/index.js not supported.
.eslintplugin.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename .eslintplugin.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/Jesper/game-engine/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

Or I rename the file to .eslintplugin.cjs and I get:

Error: Failed to load plugin 'local' declared in '.eslintrc.json': Cannot find module '../../.eslintplugin'
jespertheend commented 2 years ago

Changing the content of index.js to module.exports = require('../../.eslintplugin.cjs') seems to work but that will break all other paths. I'm not sure if there's a solution to this other than creating a new plugin.

jespertheend commented 2 years ago

eslint-plugin-rulesdir recently added support for esm. I think this is the only way for now.

ThisIsManta commented 6 months ago

This is probably too late for you but, hey, it will be done in the PR https://github.com/taskworld/eslint-plugin-local/pull/4

jespertheend commented 6 months ago

Thanks! Much appreciated :)