Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/src/module-runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function normalizeAbsoluteUrl(url: string, root: string): string {
// file:///C:/root/id.js -> C:/root/id.js
if (url.startsWith('file://')) {
// 8 is the length of "file:///"
url = url.slice(isWindows ? 8 : 7)
url = decodeURI(url.slice(isWindows ? 8 : 7))
}

// strip root from the URL because fetchModule prefers a public served url path
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const msg = 'works'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const msg = 'works'
14 changes: 14 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,17 @@ test('json', async () => {
)
expect(json?.code.length).toMatchInlineSnapshot(`61`)
})

test('file url', async () => {
const server = await createDevServer()

const mod = await server.ssrLoadModule(
new URL('./fixtures/file-url/test.js', import.meta.url).href,
)
expect(mod.msg).toBe('works')

const modWithSpace = await server.ssrLoadModule(
new URL('./fixtures/file-url/test space.js', import.meta.url).href,
)
expect(modWithSpace.msg).toBe('works')
})