Skip to content

Commit

Permalink
fix(config): skip resolve builtin modules (#10420)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Oct 12, 2022
1 parent f248e65 commit ecba3f8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
7 changes: 2 additions & 5 deletions packages/vite/src/node/config.ts
Expand Up @@ -25,6 +25,7 @@ import {
createDebugger,
createFilter,
dynamicImport,
isBuiltin,
isExternalUrl,
isObject,
lookupFile,
Expand Down Expand Up @@ -984,7 +985,7 @@ async function bundleConfigFile(

build.onResolve({ filter: /.*/ }, ({ path: id, importer, kind }) => {
// externalize bare imports
if (id[0] !== '.' && !isAbsolute(id)) {
if (id[0] !== '.' && !path.isAbsolute(id) && !isBuiltin(id)) {
let idFsPath = tryNodeResolve(id, importer, options, false)?.id
if (idFsPath && (isESM || kind === 'dynamic-import')) {
idFsPath = pathToFileURL(idFsPath).href
Expand Down Expand Up @@ -1115,7 +1116,3 @@ export function isDepsOptimizerEnabled(
(command === 'serve' && disabled === 'dev')
)
}

function isAbsolute(id: string) {
return path.isAbsolute(id) || path.posix.isAbsolute(id)
}
3 changes: 3 additions & 0 deletions playground/cli-module/package.json
Expand Up @@ -8,5 +8,8 @@
"build": "vite build",
"debug": "node --inspect-brk ../../packages/vite/bin/vite",
"serve": "vite preview"
},
"devDependencies": {
"url": "^0.11.0"
}
}
6 changes: 6 additions & 0 deletions playground/cli-module/vite.config.js
@@ -1,5 +1,11 @@
// eslint-disable-next-line import/no-nodejs-modules
import { URL } from 'url'
import { defineConfig } from 'vite'

// make sure bundling works even if `url` refers to the locally installed
// `url` package instead of the built-in `url` nodejs module
globalThis.__test_url = URL

export default defineConfig({
server: {
host: 'localhost'
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ecba3f8

Please sign in to comment.