@@ -51,7 +51,7 @@ export function validateImportPlugin(): Plugin {
51
51
if ( this . environment . mode === 'dev' ) {
52
52
if ( id . startsWith ( `\0virtual:vite-rsc/validate-imports/invalid/` ) ) {
53
53
const chain = getImportChainDev ( this . environment , id )
54
- const error = formatError ( chain , this . environment . name )
54
+ const error = formatError ( chain )
55
55
if ( error ) {
56
56
this . error ( {
57
57
id : chain [ 1 ] ,
@@ -68,15 +68,15 @@ export function validateImportPlugin(): Plugin {
68
68
this ,
69
69
'\0virtual:vite-rsc/validate-imports/invalid/server-only' ,
70
70
)
71
- const serverOnlyError = formatError ( serverOnly , this . environment . name )
71
+ const serverOnlyError = formatError ( serverOnly )
72
72
if ( serverOnlyError ) {
73
73
throw new Error ( serverOnlyError )
74
74
}
75
75
const clientOnly = getImportChainBuild (
76
76
this ,
77
77
'\0virtual:vite-rsc/validate-imports/invalid/client-only' ,
78
78
)
79
- const clientOnlyError = formatError ( clientOnly , this . environment . name )
79
+ const clientOnlyError = formatError ( clientOnly )
80
80
if ( clientOnlyError ) {
81
81
throw new Error ( clientOnlyError )
82
82
}
@@ -117,14 +117,12 @@ function getImportChainBuild(ctx: Rollup.PluginContext, id: string): string[] {
117
117
return chain
118
118
}
119
119
120
- function formatError (
121
- chain : string [ ] ,
122
- environmentName : string ,
123
- ) : string | undefined {
120
+ function formatError ( chain : string [ ] ) : string | undefined {
124
121
if ( chain . length === 0 ) return
125
122
const id = chain [ 0 ] !
126
123
const source = id . slice ( id . lastIndexOf ( '/' ) + 1 )
127
- let result = `'${ source } ' cannot be imported in '${ environmentName } ' environment:\n`
124
+ const buildName = source === 'server-only' ? 'client' : 'server'
125
+ let result = `'${ source } ' cannot be imported in ${ buildName } build:\n`
128
126
result += chain
129
127
. slice ( 1 , 6 )
130
128
. map (
0 commit comments