@@ -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 )
54
+ const error = formatError ( chain , this . environment . name )
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 )
71
+ const serverOnlyError = formatError ( serverOnly , this . environment . name )
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 )
79
+ const clientOnlyError = formatError ( clientOnly , this . environment . name )
80
80
if ( clientOnlyError ) {
81
81
throw new Error ( clientOnlyError )
82
82
}
@@ -117,12 +117,15 @@ function getImportChainBuild(ctx: Rollup.PluginContext, id: string): string[] {
117
117
return chain
118
118
}
119
119
120
- function formatError ( chain : string [ ] ) : string | undefined {
120
+ function formatError (
121
+ chain : string [ ] ,
122
+ environmentName : string ,
123
+ ) : string | undefined {
121
124
if ( chain . length === 0 ) return
122
125
const id = chain [ 0 ] !
123
126
const source = id . slice ( id . lastIndexOf ( '/' ) + 1 )
124
127
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`
126
129
result += chain
127
130
. slice ( 1 , 6 )
128
131
. map (
0 commit comments