Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): skip resolve builtin modules #10420

Merged
merged 3 commits into from Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.