Skip to content

Use meta.url as the argument to createRequire() when loading a module#9310

Closed
penalosa wants to merge 1 commit intovitest-dev:mainfrom
penalosa:penalosa/use-url-for-create-require
Closed

Use meta.url as the argument to createRequire() when loading a module#9310
penalosa wants to merge 1 commit intovitest-dev:mainfrom
penalosa:penalosa/use-url-for-create-require

Conversation

@penalosa
Copy link
Copy Markdown
Contributor

@penalosa penalosa commented Dec 20, 2025

Description

When creating a require() function using createRequire(), pass in the URL rather than the filename. Passing in the filename can cause bugs on Windows, and error messages along the lines of TypeError: The argument 'path' The argument must be a file URL object, a file URL string, or an absolute path string..

This matches the implementation in vite-node: https://github.com/antfu-collective/vite-node/blob/63e2a8111cb674335823746a5df87eae666eee76/src/client.ts#L550

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.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

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:.

@netlify
Copy link
Copy Markdown

netlify bot commented Dec 20, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit ef4364a
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6945fa24cb942300086e711d
😎 Deploy Preview https://deploy-preview-9310--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@sheremet-va
Copy link
Copy Markdown
Member

This seems to break some tests. I don't think the isAbsolute check there is correct now

// \x00 is a rollup convention for virtual files,
// it is not allowed in actual file names
if (filename[0] === '\x00' || !isAbsolute(filename)) {
if ((filename[0] === '\x00' || !isAbsolute(filename))) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why the extra params here?

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