Skip to content

Commit 7740b6d

Browse files
committed
tweak
1 parent 2889a48 commit 7740b6d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/plugin-rsc/src/plugins/validate-import.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function validateImportPlugin(): Plugin {
5151
if (this.environment.mode === 'dev') {
5252
if (id.startsWith(`\0virtual:vite-rsc/validate-imports/invalid/`)) {
5353
const chain = getImportChainDev(this.environment, id)
54-
const error = formatError(chain)
54+
const error = formatError(chain, this.environment.name)
5555
if (error) {
5656
this.error({
5757
id: chain[1],
@@ -68,15 +68,15 @@ export function validateImportPlugin(): Plugin {
6868
this,
6969
'\0virtual:vite-rsc/validate-imports/invalid/server-only',
7070
)
71-
const serverOnlyError = formatError(serverOnly)
71+
const serverOnlyError = formatError(serverOnly, this.environment.name)
7272
if (serverOnlyError) {
7373
throw new Error(serverOnlyError)
7474
}
7575
const clientOnly = getImportChainBuild(
7676
this,
7777
'\0virtual:vite-rsc/validate-imports/invalid/client-only',
7878
)
79-
const clientOnlyError = formatError(clientOnly)
79+
const clientOnlyError = formatError(clientOnly, this.environment.name)
8080
if (clientOnlyError) {
8181
throw new Error(clientOnlyError)
8282
}
@@ -117,12 +117,15 @@ function getImportChainBuild(ctx: Rollup.PluginContext, id: string): string[] {
117117
return chain
118118
}
119119

120-
function formatError(chain: string[]): string | undefined {
120+
function formatError(
121+
chain: string[],
122+
environmentName: string,
123+
): string | undefined {
121124
if (chain.length === 0) return
122125
const id = chain[0]!
123126
const source = id.slice(id.lastIndexOf('/') + 1)
124127
const buildName = source === 'server-only' ? 'client' : 'server'
125-
let result = `'${source}' cannot be imported in ${buildName} build:\n`
128+
let result = `'${source}' cannot be imported in ${buildName} build ('${environmentName}' environment):\n`
126129
result += chain
127130
.slice(1, 6)
128131
.map(

0 commit comments

Comments
 (0)