Skip to content

fix(vite-node): provide import.meta.filename and dirname #5011

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

Merged
merged 5 commits into from
Jan 19, 2024

Conversation

sheremet-va
Copy link
Member

Description

Fixes #5010

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

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link

netlify bot commented Jan 19, 2024

Deploy Preview for fastidious-cascaron-4ded94 ready!

Name Link
🔨 Latest commit cb09af0
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/65aa425fc48b6f0008aa6993
😎 Deploy Preview https://deploy-preview-5011--fastidious-cascaron-4ded94.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 site configuration.

@sheremet-va sheremet-va merged commit 7314857 into vitest-dev:main Jan 19, 2024
@sheremet-va sheremet-va deleted the fix/import-meta branch January 19, 2024 17:56
return await this.createModule(identifier)
}

public async resolve(specifier: string, parent: string) {
public resolve(specifier: string, parent: string) {
Copy link
Member

Choose a reason for hiding this comment

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

What's behind this change? I'm now running into error where resolveModule is passing Promise to createModule. Then this part:

if (identifier.startsWith('data:'))

... crashes with error

TypeError: identifier.startsWith is not a function
 ❯ ExternalModulesExecutor.getModuleInformation ../../packages/vitest/dist/vendor/vm.UXtVveu9.js:575:20
 ❯ ExternalModulesExecutor.createModule ../../packages/vitest/dist/vendor/vm.UXtVveu9.js:597:38
 ❯ ExternalModulesExecutor.resolveModule ../../packages/vitest/dist/vendor/vm.UXtVveu9.js:505:23
 ❯ ../../packages/vitest/dist/vendor/vm.UXtVveu9.js:258:58
 ❯ ModuleWrap.<anonymous> node:internal/vm/module:306:30
 ❯ SourceTextModule.<computed> node:internal/vm/module:305:36
 ❯ SourceTextModule.link node:internal/vm/module:199:22
 ❯ EsmExecutor.evaluateModule ../../packages/vitest/dist/vendor/vm.UXtVveu9.js:258:11
 ❯ ExternalModulesExecutor.import ../../packages/vitest/dist/vendor/vm.UXtVveu9.js:621:20
 ❯ VitestExecutor.interopedImport ../../packages/vite-node/dist/client.mjs:383:28

And by debugging the identifier there, it's Promise and not string.

This can be reproduced with test/run tests. The exec-argv one is crashing with vmThreads.

Copy link
Member

@AriPerkkio AriPerkkio Jan 25, 2024

Choose a reason for hiding this comment

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

import.meta.resolve is async. This is on Node v18.17.1:

> console.log(nativeResolve.toString())

async function resolve(specifier, parentUrl = defaultParentUrl) {
    return PromisePrototypeThen(
      asyncESM.esmLoader.resolve(specifier, parentUrl),
      ({ url }) => url,
      (error) => (
        error.code === 'ERR_UNSUPPORTED_DIR_IMPORT' ?
          error.url : PromiseReject(error)),
    );
  }

Though it's not in sources: https://github.com/nodejs/node/blob/6ae20aa63de78294b18d5015481485b7cd8fbb60/lib/internal/modules/esm/initialize_import_meta.js#L22

Oh well

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.

import.meta.filename and import.meta.dirname is undefined on Node.js Latest LTS v20.11.0
2 participants