infctr/eslint-plugin-typescript-sort-keys

Error when trying to use this in an ESM context

osmestad opened this issue · 1 comments

Hey, I get an error when trying to include this plugin using ES module syntax, the error is:

(node:96667) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)

Oops! Something went wrong! :(

ESLint: 8.48.0

/Users/oyvind/dev/eslint-config-tidal/node_modules/eslint-plugin-typescript-sort-keys/lib/index.esm.js:1
import { AST_NODE_TYPES, AST_TOKEN_TYPES, ESLintUtils } from '@typescript-eslint/experimental-utils';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

I tested changing the file name (from lib/index.esm.js to lib/index.mjs) that seems to work for me at least (the other option, setting "type": "module" probably also would work, but that might have bigger consequences for other usages I assume)

amritk commented

hey @osmestad thanks for the fix, I opened a PR but in the meanwhile I setup a branch with the build files if you want to use it.

"eslint-plugin-typescript-sort-keys": "github:amritk/eslint-plugin-typescript-sort-keys#build",