diff --git a/packages/vite/package.json b/packages/vite/package.json index acc7e93c313c70..43419bfc4be8b4 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -79,7 +79,6 @@ "acorn": "^8.6.0", "acorn-class-fields": "^1.0.0", "acorn-static-class-features": "^1.0.0", - "builtin-modules": "^3.2.0", "cac": "6.7.9", "chalk": "^4.1.2", "chokidar": "^3.5.2", diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 23f41b769b2fe5..4f005f21c3cf54 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -12,7 +12,7 @@ import { ENV_PUBLIC_PATH } from './constants' import resolve from 'resolve' -import builtins from 'builtin-modules' +import { builtinModules } from 'module' import { FSWatcher } from 'chokidar' import remapping from '@ampproject/remapping' import { @@ -37,10 +37,26 @@ export const flattenId = (id: string): string => export const normalizeId = (id: string): string => id.replace(/(\s*>\s*)/g, ' > ') +//TODO: revisit later to see if the edge case that "compiling using node v12 code to be run in node v16 in the server" is what we intend to support. +const builtins = new Set([ + ...builtinModules, + 'assert/strict', + 'diagnostics_channel', + 'dns/promises', + 'fs/promises', + 'path/posix', + 'path/win32', + 'readline/promises', + 'stream/consumers', + 'stream/promises', + 'stream/web', + 'timers/promises', + 'util/types', + 'wasi' +]) + export function isBuiltin(id: string): boolean { - const deepMatch = id.match(deepImportRE) - id = deepMatch ? deepMatch[1] || deepMatch[2] : id - return builtins.includes(id) + return builtins.has(id.replace(/^node:/, '')) } export function moduleListContains( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2e51778d7bb0d1..a7011891db1cbc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -700,7 +700,6 @@ importers: acorn: ^8.6.0 acorn-class-fields: ^1.0.0 acorn-static-class-features: ^1.0.0 - builtin-modules: ^3.2.0 cac: 6.7.9 chalk: ^4.1.2 chokidar: ^3.5.2 @@ -779,7 +778,6 @@ importers: acorn: 8.6.0 acorn-class-fields: 1.0.0_acorn@8.6.0 acorn-static-class-features: 1.0.0_acorn@8.6.0 - builtin-modules: 3.2.0 cac: 6.7.9 chalk: 4.1.2 chokidar: 3.5.2