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(vitest): support older NodeJS with async import.meta.resolve #5045

Merged

Conversation

AriPerkkio
Copy link
Member

Description

import.meta.resolve can be asynchronous in older Node versions like my 18.17.1:

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Jan 25, 2024

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit ae1d72f
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/65b289f5689a1f0008730396

@sheremet-va sheremet-va changed the title fix(vite-node): support older NodeJS with async import.meta.resolve fix(vitest): support older NodeJS with async import.meta.resolve Jan 25, 2024
Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Looks good!

If I remember correctly, there is one more relatively recent change with --experimental-import-meta-resolve regarding whether it throws or not when not found:

NodeJS was throwing an error at some point, but Web spec doesn't throw, so NodeJS aligned with it. Does anyone know if Vitest's vm could be affected by this behavior?

@AriPerkkio AriPerkkio merged commit cf5641a into vitest-dev:main Jan 26, 2024
18 of 19 checks passed
@AriPerkkio AriPerkkio deleted the fix/import-meta-resolve-async-handling branch January 26, 2024 05:10
@sheremet-va
Copy link
Member

Does anyone know if Vitest's vm could be affected by this behavior?

Oh we need to test this, probably not much has changed in terms of code running because the error will just move to the loader, but this is not how Node works, so it's a potential bug

@hi-ogawa
Copy link
Contributor

Oh we need to test this, probably not much has changed in terms of code running because the error will just move to the loader, but this is not how Node works, so it's a potential bug

Right, I expected it would be an error anyway, but it looks like there is a slight difference after v20.6.0 (which started non-throwing behavior). I added a test case here #5053 and will investigate if there is a way to surface an error similar to node.

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

Successfully merging this pull request may close these issues.

3 participants