diff --git a/src/lib/build/esmShPlugin.ts b/src/lib/build/esmShPlugin.ts index ff6524d7..b79208cb 100644 --- a/src/lib/build/esmShPlugin.ts +++ b/src/lib/build/esmShPlugin.ts @@ -19,7 +19,7 @@ export function esmShPlugin(dependencies: Record): Plugin { : `${packageName}@${version}`; return { - path: `https://esm.sh/${specifier}`, + path: `https://esm.sh/${specifier}?external=react,react-dom`, namespace: 'http', }; } @@ -28,9 +28,10 @@ export function esmShPlugin(dependencies: Record): Plugin { // Handle relative or absolute imports inside esm.sh modules build.onResolve({ filter: /.*/, namespace: 'http' }, (args) => { const baseURL = new URL(args.importer); // e.g., https://esm.sh/react-dom/client - const fullURL = new URL(args.path, baseURL).toString(); // resolve "/x" → full URL + const fullURL = new URL(args.path, baseURL); // resolve "/x" → full URL + fullURL.searchParams.set('external', 'react,react-dom'); // ensure react is external return { - path: fullURL, + path: fullURL.toString(), namespace: 'http', }; });