fix(vite-node): provide import.meta.filename and dirname#5011
fix(vite-node): provide import.meta.filename and dirname#5011sheremet-va merged 5 commits intovitest-dev:mainfrom
Conversation
✅ Deploy Preview for fastidious-cascaron-4ded94 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
| } | ||
|
|
||
| public async resolve(specifier: string, parent: string) { | ||
| public resolve(specifier: string, parent: string) { |
There was a problem hiding this comment.
What's behind this change? I'm now running into error where resolveModule is passing Promise to createModule. Then this part:
... 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.
There was a problem hiding this comment.
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
Description
Fixes #5010
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.