Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to use this in an ESM context #68

Open
osmestad opened this issue Sep 1, 2023 · 1 comment
Open

Error when trying to use this in an ESM context #68

osmestad opened this issue Sep 1, 2023 · 1 comment

Comments

@osmestad
Copy link

osmestad commented Sep 1, 2023

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
Copy link
Contributor

amritk commented Oct 15, 2023

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",

infctr added a commit that referenced this issue Oct 15, 2023
fix(#68): esm for new flat config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants