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

Fix ERR_UNSUPPORTED_ESM_URL_SCHEME error on Windows #7383

Merged
merged 3 commits into from Dec 10, 2023
Merged

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented Dec 10, 2023

Which issue, if any, is this issue related to?

close #7382

Is there anything in the PR that needs further explanation?

No, it's self-explanatory.

@JounQin JounQin added the type: bug a problem with a feature or rule label Dec 10, 2023
Copy link

changeset-bot bot commented Dec 10, 2023

🦋 Changeset detected

Latest commit: 2bd6507

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
stylelint Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jeddy3 jeddy3 removed the type: bug a problem with a feature or rule label Dec 10, 2023
@jeddy3 jeddy3 changed the title fix: nodejs does not accept absolute Windows paths Fix ERR_UNSUPPORTED_ESM_URL_SCHEME error on Windows Dec 10, 2023
@jeddy3
Copy link
Member

jeddy3 commented Dec 10, 2023

@JounQin Thank you for looking into this!

Is it possible to add tests to cover this scenario?

And do we also need to use this approach for plugins and custom formatters?

(FYI, I removed the bug label to be consistent with our guidelines).

@JounQin
Copy link
Member Author

JounQin commented Dec 10, 2023

Is it possible to add tests to cover this scenario?

I'm not quite familiar with how to test such edge cases.

And do we also need to use this approach for plugins and custom formatters?

If they may be loaded with absolute path, then yes, otherwise there is no need do it.

(FYI, I removed the bug label to be consistent with our guidelines).

Can we remove such unused labels in repository preset?

@JounQin
Copy link
Member Author

JounQin commented Dec 10, 2023

@ybiquitous I think the latest change e547bf4 requested makes more problems than it wants to resolve.

I think we should just revert this commit, only import() will be affected by this issue.

lib/getPostcssResult.mjs Outdated Show resolved Hide resolved
Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JounQin Can we fix getModulePath() instead as #7382 (comment)?

@JounQin
Copy link
Member Author

JounQin commented Dec 10, 2023

@ybiquitous
Copy link
Member

more problems than it wants to resolve

Just curious, what problem?

@JounQin
Copy link
Member Author

JounQin commented Dec 10, 2023

@ybiquitous
Copy link
Member

Ah, you didn't need to force-push since we couldn't find the failed CI easily.

@ybiquitous
Copy link
Member

ybiquitous commented Dec 10, 2023

I found the failure cause of e547bf4. The extends config doesn't use dynamic import(). So, we cannot fix getModulePath() now.

However, I think we must fix dynamic import() also plugins, not only custom syntaxes:

pluginImport = await import(pluginLookup);

So, how about adding a tiny utility to wrap dynamic import()? For example,

// lib/utils/dynamicImport.mjs
export default dynamicImport(path) {
  const fixedPath = isAbsolute(path) ? pathToFileURL(path).toString() : path;

  return import(fixedPath);
}

@JounQin
Copy link
Member Author

JounQin commented Dec 10, 2023

Sure, a tiny util is fine enough. I didn't find that usage previously. Wait minutes.

Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! LGTM 👍🏼

@JounQin JounQin merged commit dde101d into main Dec 10, 2023
16 checks passed
@JounQin JounQin deleted the fix/import_esm_win branch December 10, 2023 15:54
@ybiquitous ybiquitous mentioned this pull request Dec 10, 2023
8 tasks
@CrOrc
Copy link

CrOrc commented Dec 28, 2023

The same error is thrown in cli.mjs when running
stylelint "**/*.css" --custom-formatter="./path/to/formatter.js"

@JounQin
Copy link
Member Author

JounQin commented Dec 28, 2023

@CrOrc You need to create a new issue with online and runnable reproduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Fix ERR_UNSUPPORTED_ESM_URL_SCHEME error on Windows
4 participants