Skip to content

Commit b628464

Browse files
authoredJan 7, 2025··
fix(vite-node): fix mandatory node prefix (#7179)
1 parent 57c8740 commit b628464

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
 

‎packages/vite-node/src/utils.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ export function isInternalRequest(id: string): boolean {
6868
return internalRequestRegexp.test(id)
6969
}
7070

71-
const prefixedBuiltins = new Set(['node:test'])
71+
// https://nodejs.org/api/modules.html#built-in-modules-with-mandatory-node-prefix
72+
const prefixedBuiltins = new Set([
73+
'node:sea',
74+
'node:sqlite',
75+
'node:test',
76+
'node:test/reporters',
77+
])
7278

7379
const builtins = new Set([
7480
...builtinModules,

‎test/config/test/node-sqlite.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect, test } from 'vitest'
2+
import { runInlineTests, ts } from '../../test-utils'
3+
4+
const nodeMajor = Number(process.version.slice(1).split('.')[0])
5+
6+
test.runIf(nodeMajor >= 22)('import node:sqlite', async () => {
7+
const { vitest, results } = await runInlineTests({
8+
'vitest.config.ts': {
9+
test: {
10+
pool: 'forks',
11+
poolOptions: {
12+
forks: {
13+
execArgv: ['--experimental-sqlite'],
14+
},
15+
},
16+
},
17+
},
18+
'basic.test.ts': ts`
19+
import { test, expect } from 'vitest'
20+
import sqlite from 'node:sqlite'
21+
22+
test('sqlite', () => {
23+
console.log(sqlite)
24+
})
25+
`,
26+
})
27+
expect(vitest.stderr).toBe('')
28+
expect(results[0].ok()).toBe(true)
29+
})

0 commit comments

Comments
 (0)
Please sign in to comment.