markdalgleish / static-site-generator-webpack-plugin

Minimal, unopinionated static site generator powered by webpack
MIT License
1.61k stars 97 forks source link

Webpack 5 - document is not defined #143

Open schwjustin opened 2 years ago

schwjustin commented 2 years ago

In my webpack.config.js file I have:

output: {
    ...
    libraryTarget: "umd",
    globalObject: "this",
},

...

new StaticSiteGeneratorPlugin({
    locals: {},
    globals: {
        window: {},
    },
}),
ERROR in ReferenceError: document is not defined
    at evalmachine.<anonymous>:127444:36
    at evalmachine.<anonymous>:127466:13
    at evalmachine.<anonymous>:133637:12
    at webpackUniversalModuleDefinition (evalmachine.<anonymous>:3:20)
    at evalmachine.<anonymous>:10:3
    at Script.runInContext (node:vm:139:12)
    at Script.runInNewContext (node:vm:144:17)
    at module.exports (/Users/justinschwartz/Documents/GitHub/chrome-extension/node_modules/eval/eval.js:84:12)
    at /Users/justinschwartz/Documents/GitHub/chrome-extension/node_modules/static-site-generator-webpack-plugin/index.js:42:22
    at fn (/Users/justinschwartz/Documents/GitHub/chrome-extension/node_modules/webpack/lib/Compilation.js:509:9)

webpack 5.72.0 compiled with 1 error in 47986 ms
Patysko commented 1 year ago

Add to globals document you can mock that with JS-DOM library globals: { document: {}, },