You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: packages/vite/src/node/plugins/resolve.ts
+34-18
Original file line number
Diff line number
Diff line change
@@ -133,6 +133,7 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
133
133
const{
134
134
root,
135
135
isProduction,
136
+
isBuild,
136
137
asSrc,
137
138
ssrConfig,
138
139
preferRelative =false,
@@ -448,27 +449,42 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
448
449
449
450
load(id){
450
451
if(id.startsWith(browserExternalId)){
451
-
if(isProduction){
452
-
// return `export default {}`
453
-
// The rolldown missing export is always error level, it will break build.
454
-
// So here using the cjs module to avoid it.
455
-
return`module.exports = {}`
452
+
if(isBuild){
453
+
if(isProduction){
454
+
// return `export default {}`
455
+
// The rolldown missing export is always error level, it will break build.
456
+
// So here using the cjs module to avoid it.
457
+
return`module.exports = {}`
458
+
}else{
459
+
id=id.slice(browserExternalId.length+1)
460
+
// The rolldown using esbuild interop helper, so here copy the proxy module from https://github.com/vitejs/vite/blob/main/packages/vite/src/node/optimizer/esbuildDepPlugin.ts#L259-------
461
+
return`\
462
+
module.exports = Object.create(new Proxy({}, {
463
+
get(_, key) {
464
+
if (
465
+
key !== '__esModule' &&
466
+
key !== '__proto__' &&
467
+
key !== 'constructor' &&
468
+
key !== 'splice'
469
+
) {
470
+
throw new Error(\`Module "${id}" has been externalized for browser compatibility. Cannot access "${id}.\${key}" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.\`)
471
+
}
472
+
}
473
+
}))`
474
+
}
456
475
}else{
457
-
id=id.slice(browserExternalId.length+1)
458
-
// The rolldown using esbuild interop helper, so here copy the proxy module from https://github.com/vitejs/vite/blob/main/packages/vite/src/node/optimizer/esbuildDepPlugin.ts#L259-------
459
-
return`\
460
-
module.exports = Object.create(new Proxy({}, {
461
-
get(_, key) {
462
-
if (
463
-
key !== '__esModule' &&
464
-
key !== '__proto__' &&
465
-
key !== 'constructor' &&
466
-
key !== 'splice'
467
-
) {
476
+
// The dev need to return esm module.
477
+
if(isProduction){
478
+
return`export default {}`
479
+
}else{
480
+
id=id.slice(browserExternalId.length+1)
481
+
return`\
482
+
export default new Proxy({}, {
483
+
get(_, key) {
468
484
throw new Error(\`Module "${id}" has been externalized for browser compatibility. Cannot access "${id}.\${key}" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.\`)
0 commit comments