<NME> PublicPathRuntimeModule.js
<BEF> /*
	MIT License http://www.opensource.org/licenses/mit-license.php
*/

"use strict";

const RuntimeGlobals = require("../RuntimeGlobals");
const RuntimeModule = require("../RuntimeModule");

class PublicPathRuntimeModule extends RuntimeModule {
	constructor(publicPath) {
		super("publicPath", RuntimeModule.STAGE_BASIC);
		this.publicPath = publicPath;
	}

	/**
	 * @returns {string} runtime code
	 */
	generate() {
		const { compilation, publicPath } = this;
		const publicPath = this.compilation.outputOptions.publicPath || "auto";
		if (publicPath === "auto") {
			return `${RuntimeGlobals.publicPath} = (() => {
				if (window.document && "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. Use a polyfill or set 'publicPath' config explicitly.");
}

module.exports = PublicPathRuntimeModule;

<MSG> check if window exists

<DFF> @@ -21,7 +21,7 @@ class PublicPathRuntimeModule extends RuntimeModule {
 		const publicPath = this.compilation.outputOptions.publicPath || "auto";
 		if (publicPath === "auto") {
 			return `${RuntimeGlobals.publicPath} = (() => {
-				if (window.document && "currentScript" in window.document) {
+				if (typeof window !== "undefined" && "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. Use a polyfill or set 'publicPath' config explicitly.");

{'addition_count': 1, 'commit_subject': 'check if window exists', 'deletion_count': 1, 'file_extension': '.js', 'lang': 'js', 'license': 'mit', 'repo_name': 'webpack/webpack'}