Skip to content

Commit

Permalink
fix(resolve): warn if node-like builtin was imported when `resolve.bu…
Browse files Browse the repository at this point in the history
…iltin` is empty (#19312)
  • Loading branch information
sapphi-red authored Feb 3, 2025
1 parent 4583781 commit b7aba0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/vite/src/node/__tests__/resolve.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join } from 'node:path'
import { describe, expect, onTestFinished, test } from 'vitest'
import { describe, expect, onTestFinished, test, vi } from 'vitest'
import { createServer } from '../server'
import { createServerModuleRunner } from '../ssr/runtime/serverModuleRunner'
import type { EnvironmentOptions, InlineConfig } from '../config'
Expand Down Expand Up @@ -176,6 +176,11 @@ describe('file url', () => {
idToResolve: string
}) {
const server = await createServer(getConfig(targetEnv, builtins))
vi.spyOn(server.config.logger, 'warn').mockImplementationOnce(
(message) => {
throw new Error(message)
},
)
onTestFinished(() => server.close())

return server.environments[testEnv]?.pluginContainer.resolveId(
Expand Down Expand Up @@ -218,7 +223,7 @@ describe('file url', () => {
idToResolve: 'node:fs',
}),
).rejects.toThrowError(
/Automatically externalized node built-in module "node:fs"/,
/warning: Automatically externalized node built-in module "node:fs"/,
)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ export function resolvePlugin(
)}"`
}
message += `. Consider adding it to environments.${this.environment.name}.external if it is intended.`
this.error(message)
this.warn(message)
}

return options.idOnly
Expand Down

0 comments on commit b7aba0b

Please sign in to comment.