Skip to content

Commit 31b467f

Browse files
Fix issue with relative URL in dynamic import (#3986)
Before, when using the global bundle, we get the `Uncaught (in promise) TypeError: Failed to resolve module specifier './index.js'. The base URL is about:blank because import() is called from a CORS-cross-origin script.` error.
1 parent 3d99da8 commit 31b467f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/prism.global.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
// In browser and imported via non-ESM
2-
import('./index.js').then(({ default: prism }) => ((globalThis as any).Prism = prism));
1+
const currentScript = globalThis.document?.currentScript as HTMLScriptElement;
2+
if (currentScript) {
3+
// In browser and imported via non-ESM
4+
const url = new URL('./index.js', currentScript.src);
5+
6+
void import(url.toString()).then(({ default: prism }) => ((globalThis as any).Prism = prism));
7+
}

0 commit comments

Comments
 (0)