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

incompatible with eslint-plugin-import #288

Closed
olsonpm opened this issue Jan 20, 2024 · 3 comments
Closed

incompatible with eslint-plugin-import #288

olsonpm opened this issue Jan 20, 2024 · 3 comments

Comments

@olsonpm
Copy link

olsonpm commented Jan 20, 2024

Due to a top-level await in pnpResolver.js, eslint-plugin-import is unable to parse this module.

I understand if you don't want to support this use-case, as the owner of that module is particularly against native esm. However if pnp is able to be imported directly now or if there's some other way to work around the top level await then that would be helpful.

For now I'm removing pnp in a fork since I have no plans on using yarn's pnp.

Thanks for this library :)

@koshic
Copy link
Collaborator

koshic commented Jan 20, 2024

@olsonpm, eslint-plugin-import has no parser, eslint has it. And eslint supports top-level await without any issues. Could you please provide a more details / steps to reproduce?

Generally speaking, it's ok to fix some library a bit to provide compatibility with popular tools, but we need to understand the root cause.

@olsonpm
Copy link
Author

olsonpm commented Jan 20, 2024

Here's a reproduction

$ git clone git@github.com:olsonpm/repro.git
$ cd repro
$ git checkout esmock-issue-288
$ npm ci
$ npx eslint index.mjs

/path/to/repro/index.mjs
  1:20  error    Parse errors in imported module 'esmock': Cannot use keyword 'await' outside an async function (2:8171)  import/namespace
  1:20  error    Parse errors in imported module 'esmock': Cannot use keyword 'await' outside an async function (2:8171)  import/default
  1:20  warning  Parse errors in imported module 'esmock': Cannot use keyword 'await' outside an async function (2:8171)  import/no-named-as-default
  1:20  warning  Parse errors in imported module 'esmock': Cannot use keyword 'await' outside an async function (2:8171)  import/no-named-as-default-member

✖ 4 problems (2 errors, 2 warnings)

I'll look into the parser detail you mention to better understand the issue


edit: okay I fixed the repro and updated the error text

@olsonpm olsonpm closed this as completed Jan 20, 2024
@olsonpm
Copy link
Author

olsonpm commented Jan 20, 2024

looks like I needed to add ecmaVersion: 2022 or later so you were right, it had to do with my configuration of the eslint parser.

I haven't encountered this issue before I think because typically eslint rules are specific to a projects' own files. Looks like the import plugin parses other module's files (necessarily of course), which then means the parser configuration needs to support other library's code.

Sorry for the noise

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