Skip to content

test(v6): add runner dynamic import test#17422

Closed
hi-ogawa wants to merge 4 commits into
vitejs:v6/environment-apifrom
hi-ogawa:test-runner-import-absolute
Closed

test(v6): add runner dynamic import test#17422
hi-ogawa wants to merge 4 commits into
vitejs:v6/environment-apifrom
hi-ogawa:test-runner-import-absolute

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented Jun 8, 2024

Copy link
Copy Markdown
Contributor

Description

I'm testing alpha.18 hi-ogawa/vite-environment-examples#91 and found that import(/* @vite-ignore */ someAboslutePath) is returning a duplicate module. I added a failing test case in this PR.

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Comment thread packages/vite/src/node/__tests__/dev.spec.ts Outdated
@sheremet-va

sheremet-va commented Jul 19, 2024

Copy link
Copy Markdown
Member

This does seem consistent with how Vite works: Vite server expects the URL, but instead, you pass down the full path. The server says that this module doesn't exist:

environment.moduleGraph.getModuleByUrl('/src/basic.js') // exists
environment.moduleGraph.getModuleByUrl('<root>/src/basic.js') // doesn't exist

There is an inconsistency when you call runner.import directly - it will shorten the path to avoid accidental duplicated modules. So we should either make it fail, or also shorten the path for dynamic imports inside the processed code 🤷🏻

It does seem more like a bug because in Node.js this code will work correctly 🤔

@sheremet-va

Copy link
Copy Markdown
Member

Should be fixed by 01246e5 (#16471)

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.

2 participants