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

Support query parameters in import/no-unresolved #2562

Closed
lachrist opened this issue Oct 4, 2022 · 5 comments
Closed

Support query parameters in import/no-unresolved #2562

lachrist opened this issue Oct 4, 2022 · 5 comments

Comments

@lachrist
Copy link

lachrist commented Oct 4, 2022

Passing parameters to a module can be done via the import url -- cf: https://flaming.codes/en/posts/es6-import-with-parameters. So import "./lib.mjs?foo=bar will cause node to load ./lib.mjs but it will be flagged by the import/no-unresolved rule because the file ./lib.mjs?foo=bar does not exist.

@ljharb
Copy link
Member

ljharb commented Oct 4, 2022

This plugin currently does not yet support native ESM, and node does not support query parameters in transpiled ESM.

It's a good idea regardless to never use a query string in a specifier URL, but either way, this plugin will support it once resolve supports ESM.

@ljharb ljharb closed this as completed Oct 4, 2022
@lachrist
Copy link
Author

Hi @ljharb, thanks for your answer. If you have time, could clarify two points?

This plugin currently does not yet support native ESM, and node does not support query parameters in transpiled ESM.

Are you saying that eslint-plugin-import relies on a transpiler to transform esm modules into commonjs modules? And since commonjs modules cannot be imported with query parameters, making eslint-plugin-import support query parameters is hard?

It's a good idea regardless to never use a query string in a specifier URL

Could you explain why?

@ljharb
Copy link
Member

ljharb commented Oct 10, 2022

I’m saying that eslint-plugin-import still expects a world where all ESM is transpiled into CJS.

Sure - a query string suggests that you could get a different module from what conceptually would be expected to be the same specifier. Modules aren’t supposed to be dynamic, they’re supposed to be static.

@lachrist
Copy link
Author

Oke, thanks for your time!

@joshua-farmlink
Copy link

Sorry to post in a closed issue, but I'm wondering if it would be possible to add some configuration options to ignore query strings until resolve supports ESM? In looking through past issues, I found two other threads discussing query strings for other rules such as no-duplicates and extensions, which got PRs to let you ignore the query string.

#1107
#1567

I am trying to import some SVGs with a query string e.g. example.svg?url and example.svg?raw. I have tried using ignore: ['\\?(raw|url)$'] but this isn't quite what I want, since now it's just ignoring those files and not checking if the svg file itself exists.

ShGKme added a commit to nextcloud/spreed that referenced this issue Oct 24, 2023
- Not supported by eslint-plugin-import
- import-js/eslint-plugin-import#2562

Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants