Window is not defined
See original GitHub issueHi there,
Running into this error using the webpack integration with the react-refresh/babel
plugin
packages/webpack/src/utils/createTemplate.js
// Execute the module function
const prevRefreshReg = window.$RefreshReg$; // ERROR: Window is undefined
const prevRefreshSig = window.$RefreshSig$;
I have tried modifying the globalObject
in the webpack output
to use this
, but unfortunately still doesn’t work and seems to break other things.
webpack.config below:
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OUTPUT_DIR = 'dist';
const PreactRefreshPlugin = require('@prefresh/webpack');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const mainEntries = [path.resolve(__dirname, './src/engine/client/index.tsx')];
// Exports
module.exports = {
entry: {
editor: mainEntries,
av: path.resolve(__dirname, './src/engine/client/AV/AVIndex.tsx'),
login: path.resolve(__dirname, './src/engine/client/Login/index.tsx'),
},
devServer: {
disableHostCheck: true,
port: 9000,
hot: true,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers':
'X-Requested-With, content-type, Authorization',
},
proxy: {
'/api': 'http://localhost:1234/dimsum/api',
},
},
mode: 'development',
stats: 'errors-only',
target: 'web',
devtool: 'eval-source-map',
node: {
fs: 'empty',
},
output: {
path: path.join(__dirname, OUTPUT_DIR),
pathinfo: false,
// publicPath: '/',
publicPath: 'http://localhost:9000/',
filename: 'dimsum/static/[name].pkgd.js',
chunkFilename: 'dimsum/static/[name].pkgd.js',
jsonpFunction: 'dimsumCoreJsonpFunction',
},
resolve: {
extensions: ['.wasm', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.css'],
modules: [path.resolve(__dirname, 'node_modules')],
alias: {
// 'react-dom': '@hot-loader/react-dom',
react: 'preact/compat',
'react-dom/test-utils': 'preact/test-utils',
'react-dom': 'preact/compat',
},
},
optimization: {
splitChunks: {
// chunks: 'all',
cacheGroups: {
vendor: {
chunks: 'initial',
name: 'vendor',
enforce: true,
test: /node_modules/,
},
},
},
},
// optimization: {
// // removeAvailableModules: false,
// // removeEmptyChunks: false,
// splitChunks: false,
// },
module: {
rules: [
{
test: /\.worker\.ts$/,
use: [
{
loader: 'worker-loader',
options: { inline: true },
},
{
loader: 'babel-loader',
options: {
babelrc: false,
cacheDirectory: true,
presets: [
[
'@babel/env',
{
modules: false,
targets: {
browsers: ['last 2 versions'],
},
},
],
'@babel/typescript',
'@babel/react',
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-optional-chaining',
'react-refresh/babel',
],
},
},
],
},
{
test: /\.(ts|tsx)$/,
use: [
{
loader: 'babel-loader',
options: {
babelrc: false,
cacheDirectory: true,
presets: [
[
'@babel/env',
{
modules: false,
targets: {
browsers: ['last 2 versions'],
},
},
],
'@babel/typescript',
'@babel/react',
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-optional-chaining',
'transform-mui-imports',
'babel-plugin-styled-components',
'react-refresh/babel',
],
},
},
],
},
{
test: /\.css$/,
include: /node_modules/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(ttf|otf|woff|woff2)$/,
loader: 'file-loader',
},
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new PreactRefreshPlugin(),
new MonacoWebpackPlugin({
languages: ['json', 'html', 'scss'],
}),
new MiniCssExtractPlugin({
filename: 'vendor.css',
chunkFilename: '[id].css',
}),
],
};
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to solve "window is not defined" errors in React and Next.js
How to solve "window is not defined" errors in React and Next.js · 1. First solution: typeof · 2. Second solution: the useEffect...
Read more >How to solve Next.js window is not defined
ReferenceError : window is not defined is a pretty common error you may run into when using Next.js for the first time but...
Read more >Javascript: 'window' is not defined - Stack Overflow
The window object represents an open window in a browser. Since you are not running your code within a browser, but via Windows...
Read more >referenceerror: window is not defined, how to solve
Here's how to fix the “referenceerror: window is not defined” error that you might have in Node.js or with a tool like Next.js....
Read more >[Solved] ReferenceError : window is not defined - ItsJavaScript
The ReferenceError : window is not defined error mainly occurs if you are using the window object in Node.js, React.js, Next.js.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
np, many thanks for the project!
All right, I’ll make a PR. Thank you so much for testing that!