Я получаю ошибку window not defined
при использовании веб-пакета для компиляции моего проекта, и я не могу понять, почему. Я пытался добавить разные загрузчики и установить глобальный объект равным this
, но все еще не могу заставить его работать.
Ошибка
[nodemon] starting `node build/bundle.js`
^[[A/Users/schachte/Desktop/node_modules/golden-layout/dist/goldenlayout.js:5339
} );})(window.$);
^
ReferenceError: window is not defined
at Object.<anonymous> (/Users/schachte/Desktop/node_modules/golden-layout/dist/goldenlayout.js:5339:8)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/Users/schachte/Desktop/build/bundle.js:1:6416)
at r (/Users/schachte/Desktop/build/bundle.js:1:172)
Webpack Config
const path = require("path");
const merge = require("webpack-merge");
const baseConfg = require("./webpack.base.js");
const webpackNodeExternals = require("webpack-node-externals");
const config = {
// Inform webpack that we are building a bundle for node.js
// rather than for the browser
target: "node",
// Tell webpack the root file of our
// server application
entry: [
nodeResolve("babel-polyfill"),
nodeResolve("whatwg-fetch"),
"./src/server/index.js"
],
// Tell webpack where to put the output file that is generate
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "build")
},
externals: [webpackNodeExternals()]
};
module.exports = merge(baseConfg, config);