access document through window

This commit is contained in:
Garrett Johnson 2020-08-02 20:49:48 -07:00
parent 6807bb6f6d
commit 94973fd240
1 changed files with 2 additions and 2 deletions

View File

@ -21,8 +21,8 @@ class PublicPathRuntimeModule extends RuntimeModule {
const publicPath = this.compilation.outputOptions.publicPath || "auto";
if (publicPath === "auto") {
return `${RuntimeGlobals.publicPath} = (() => {
if ("currentScript" in document) {
return document.currentScript.src.replace(/[^\\/]+$/, "");
if ("currentScript" in window.document) {
return window.document.currentScript.src.replace(/[^\\/]+$/, "");
} else {
throw new Error("Webpack: Auto public path is not supported in modules or when 'document.currentScript' is unavailable. Set 'publicPath' config explicitly.");
}