-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ssr): improve missing file error (#10880)
- Loading branch information
Showing
5 changed files
with
48 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/vite/src/node/ssr/__tests__/fixtures/modules/has-invalid-import.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// eslint-disable-next-line node/no-missing-import | ||
import { foo } from './non-existent.js' | ||
|
||
export const hello = 'world' |
23 changes: 23 additions & 0 deletions
23
packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { fileURLToPath } from 'node:url' | ||
import { expect, test } from 'vitest' | ||
import { createServer } from '../../server' | ||
|
||
const root = fileURLToPath(new URL('./', import.meta.url)) | ||
|
||
async function createDevServer() { | ||
const server = await createServer({ configFile: false, root }) | ||
server.pluginContainer.buildStart({}) | ||
return server | ||
} | ||
|
||
test('ssrLoad', async () => { | ||
expect.assertions(1) | ||
const server = await createDevServer() | ||
try { | ||
await server.ssrLoadModule('/fixtures/modules/has-invalid-import.js') | ||
} catch (e) { | ||
expect(e.message).toBe( | ||
'Failed to load url ./non-existent.js (resolved id: ./non-existent.js). Does the file exist?' | ||
) | ||
} | ||
}) |