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(resolve): warn if node-like builtin was imported when resolve.builtin is empty #19312

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -150,6 +150,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 @@ -192,7 +197,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 @@ -426,7 +426,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