Closed enzy closed 4 years ago
The fix for https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/88 might address this (not 100% sure, but it's possible)
My guess is that you've included the react-refresh/babel
plugin to process node_modules
. This will break because some code (as used by Webpack and WDS) will inevitably run before the plugin.
Indeed. What a great guess! The cause was missing exclude: /node_modules/
in js/ts loaders with babel-loader
.
Thanks a lot, I was stuck on this for so long 🙏
My guess is that you've included the
react-refresh/babel
plugin to processnode_modules
. This will break because some code (as used by Webpack and WDS) will inevitably run before the plugin.
You save my life <3
I have recently introduced the plugin and have got the error only in production. The exclude
setting is applied to my webpack.common.js
and the plugin has to do nothing with my production config, so what'd be wrong here?
I have recently introduced the plugin and have got the error only in production. The
exclude
setting is applied to mywebpack.common.js
and the plugin has to do nothing with my production config, so what'd be wrong here?
You probably need to exclude the react-refresh/babel
plugin for your production build, or properly set NODE_ENV
for the build process as well.
I had a separate babel.config.js
and there was a development-only setting for the plugin. However it seemed not working so that I merged the settings into webpack configs and now it seems fine. Would this be a workaround for everyone or just for me?
I had a separate
babel.config.js
and there was a development-only setting for the plugin. However it seemed not working so that I merged the settings into webpack configs and now it seems fine. Would this be a workaround for everyone or just for me?
Can you share your babel.config.js
? Maybe the development
only setting was not set up correctly?
Well I have already deleted it but here is the one.
module.exports = function babel(api) {
const presets = [
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: {
version: 3,
proposals: true,
},
},
],
'@babel/preset-react',
'@babel/preset-typescript',
];
const plugins = [];
const ENV = api.env();
if (ENV === 'development') {
plugins.push('react-refresh/babel');
}
return {
presets,
plugins,
};
};
Well I have already deleted it but here is the one.
I think you didn't set NODE_ENV
to production
for the production build? That's why the api.env()
is always development
?
That was true indeed, I let the npm script call the production settings of the webpack. Because of that my production settings in the .env file is loaded into the .ts files so I thought the same environment is set to production for babel as well.
Need help, please.
I'm using @pmmmwh/react-refresh-webpack-plugin
and @react-refresh-typescript
.
Using rule:
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
getCustomTransformers: () => ({
before: [require('react-refresh-typescript').default()],
}),
},
},
],
}
Build succeded. I started dev-server with "webpack serve --config webpack.dev.js". But in browser I see: "Uncaught ReferenceError: $RefreshSig$ is not defined at ..."
optimization: {
runtimeChunk: 'single',
},
doesn't help.
When I use this:
// @ts-expect-error
global.$RefreshReg$ = () => {};
// @ts-expect-error
global.$RefreshSig$ = () => () => {};
I have errors in console like this (when open MuiDialog): _Cannot read properties of undefined (reading 'displayName') TypeError: Cannot read properties of undefined (reading 'displayName') at getDisplayName (chrome-extension://fmkadmapgofadopljbjfkapdkoienihi/build/react_devtoolsbackend.js:261:19)
What I did wrong?
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"react-refresh-typescript": "^2.0.8",
"ts-loader": "^9.4.2",
"tsconfig-paths-webpack-plugin": "^4.0.0",
"typescript": "^4.9.4",
"webpack": "^5.76.3",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.13.1",
"webpack-merge": "^5.8.0"
Need help, please. I'm using
@pmmmwh/react-refresh-webpack-plugin
and@react-refresh-typescript
. Using rule:{ test: /\.tsx?$/, exclude: /node_modules/, use: [ { loader: 'ts-loader', options: { getCustomTransformers: () => ({ before: [require('react-refresh-typescript').default()], }), }, }, ], }
Build succeded. I started dev-server with "webpack serve --config webpack.dev.js". But in browser I see: "Uncaught ReferenceError: RefreshSig is not defined at ..."
optimization: { runtimeChunk: 'single', },
doesn't help.
When I use this:
// @ts-expect-error global.$RefreshReg$ = () => {}; // @ts-expect-error global.$RefreshSig$ = () => () => {};
I have errors in console like this (when open MuiDialog): _Cannot read properties of undefined (reading 'displayName') TypeError: Cannot read properties of undefined (reading 'displayName') at getDisplayName (chrome-extension://fmkadmapgofadopljbjfkapdkoienihi/build/react_devtoolsbackend.js:261:19)
What I did wrong?
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10", "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", "react-refresh-typescript": "^2.0.8", "ts-loader": "^9.4.2", "tsconfig-paths-webpack-plugin": "^4.0.0", "typescript": "^4.9.4", "webpack": "^5.76.3", "webpack-cli": "^5.0.1", "webpack-dev-server": "^4.13.1", "webpack-merge": "^5.8.0"
Can you provide your plugin configuration portions?
Here it is: plugins: [ new ReactRefreshWebpackPlugin(), new HtmlWebpackPlugin({..}), new Dotenv(), ], ... module: { rules: [ { test: /.tsx?$/, use: 'ts-loader', exclude: /node_modules/, options: { getCustomTransformers: () => ({ before: [require('react-refresh/typescript')()], }), }, }, { test: /.svg$/, type: 'asset', use: 'svgo-loader', }, { test: /.(png|jpg|jpeg|gif|ico|mp3)$/i, type: 'asset/resource', }, { test: /.(woff|woff2|eot|ttf|otf)$/i, type: 'asset/resource', generator: { filename: 'fonts/[name][ext]', }, }, ], },
I just hit this. We have a requirement to allow refreshing of a single node module. I wonder if it's possible?
It works for our Electron app, but when I try to load the file standalone in a browser this regex seems not to be satisfactory: exclude: /node_modules\/(?!@our\/package)/
But exclude: /node_modules/
works fine (except that we need to hot reload @our/package
.
Can anyone advise if/how this is possible?
I just hit this. We have a requirement to allow refreshing of a single node module. I wonder if it's possible?
It works for our Electron app, but when I try to load the file standalone in a browser this regex seems not to be satisfactory:
exclude: /node_modules\/(?!@our\/package)/
But
exclude: /node_modules/
works fine (except that we need to hot reload@our/package
.Can anyone advise if/how this is possible?
You probably also need to pass your package through Babel with the react-refresh/babel
plugin.
Our webpack configuration matches the readme. No other options passed to the plugin. The main difference is devServer
writeToDisk: true
option as we have a PHP backend which servers builded files. Single file entry.When we run
npm run dev-server
, the compilation step finishes without a problem:But we face the fatal error in a browser afterwards:
And it looks like
ReactRefreshEntry.js
was never called.If we run
npm run dev
which calls webpack directly, the compilation step finished successfully:And the browser console is clean and our app works fine. But the hot reload functionality is gone as there is no running dev server to get changes from.
RefreshReg
,$RefreshSig$
and$RefreshSetup$
are now present under window object.I have tried disabling everything, even the whole app/index.js file but without a success. My humble debugging suggests that ReactRefreshEntry is not called early enough. The chain goes like this:
webpack-dev-server/client/index.js → webpack-dev-server/client/socket.js → webpack-dev-server/client/clients/SockJSClient.js → sockjs-client/dist/sockjs.js → and finally
setup(env)
failing to callvar _s = $RefreshSig$();
That's where my abilities ends and wonders begin :)
Can you point me in some direction what to check and how can I provide better feedback?
Thanks!
Versions: