Skip to content

Commit

Permalink
fix(vite-node): fix mandatory node prefix (#7179)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Jan 7, 2025
1 parent 57c8740 commit b628464
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/vite-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ export function isInternalRequest(id: string): boolean {
return internalRequestRegexp.test(id)
}

const prefixedBuiltins = new Set(['node:test'])
// https://nodejs.org/api/modules.html#built-in-modules-with-mandatory-node-prefix
const prefixedBuiltins = new Set([
'node:sea',
'node:sqlite',
'node:test',
'node:test/reporters',
])

const builtins = new Set([
...builtinModules,
Expand Down
29 changes: 29 additions & 0 deletions test/config/test/node-sqlite.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, test } from 'vitest'
import { runInlineTests, ts } from '../../test-utils'

const nodeMajor = Number(process.version.slice(1).split('.')[0])

test.runIf(nodeMajor >= 22)('import node:sqlite', async () => {
const { vitest, results } = await runInlineTests({
'vitest.config.ts': {
test: {
pool: 'forks',
poolOptions: {
forks: {
execArgv: ['--experimental-sqlite'],
},
},
},
},
'basic.test.ts': ts`
import { test, expect } from 'vitest'
import sqlite from 'node:sqlite'
test('sqlite', () => {
console.log(sqlite)
})
`,
})
expect(vitest.stderr).toBe('')
expect(results[0].ok()).toBe(true)
})

0 comments on commit b628464

Please sign in to comment.