Skip to content

Commit 8fbae69

Browse files
authored
fix(config): support builtin modules and deno (#10457)
* fix(config): skip resolve builtin modules (#10420) * fix(config): partial deno support (#10446)
1 parent 94abccc commit 8fbae69

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

packages/vite/src/node/config.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
createDebugger,
2626
createFilter,
2727
dynamicImport,
28+
isBuiltin,
2829
isExternalUrl,
2930
isObject,
3031
lookupFile,
@@ -972,7 +973,11 @@ async function bundleConfigFile(
972973

973974
build.onResolve({ filter: /.*/ }, ({ path: id, importer, kind }) => {
974975
// externalize bare imports
975-
if (id[0] !== '.' && !isAbsolute(id)) {
976+
if (id[0] !== '.' && !path.isAbsolute(id) && !isBuiltin(id)) {
977+
// partial deno support as `npm:` does not work in `tryNodeResolve`
978+
if (id.startsWith('npm:')) {
979+
return { external: true }
980+
}
976981
let idFsPath = tryNodeResolve(id, importer, options, false)?.id
977982
if (idFsPath && (isESM || kind === 'dynamic-import')) {
978983
idFsPath = pathToFileURL(idFsPath).href
@@ -1103,7 +1108,3 @@ export function isDepsOptimizerEnabled(
11031108
(command === 'serve' && disabled === 'dev')
11041109
)
11051110
}
1106-
1107-
function isAbsolute(id: string) {
1108-
return path.isAbsolute(id) || path.posix.isAbsolute(id)
1109-
}

playground/cli-module/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"build": "vite build",
99
"debug": "node --inspect-brk ../../packages/vite/bin/vite",
1010
"serve": "vite preview"
11+
},
12+
"devDependencies": {
13+
"url": "^0.11.0"
1114
}
1215
}

playground/cli-module/vite.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
// eslint-disable-next-line import/no-nodejs-modules
2+
import { URL } from 'url'
13
import { defineConfig } from 'vite'
24

5+
// make sure bundling works even if `url` refers to the locally installed
6+
// `url` package instead of the built-in `url` nodejs module
7+
globalThis.__test_url = URL
8+
39
export default defineConfig({
410
server: {
511
host: 'localhost'

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)