$RefreshReg$ is not defined in web worker after upgrading to 9.4.0
See original GitHub issueBug report
I believe this is a React Refresh-related issue.
Potentially relevant:
- https://github.com/facebook/react-native/issues/25684
- https://github.com/facebook/react/blob/master/packages/react-refresh/src/__tests__/ReactFresh-test.js
Describe the bug
After upgrading to Next.js 9.4.0
, workers throw the following exception on load:
Uncaught ReferenceError: $RefreshReg$ is not defined
at Module.eval (blocks.ts:239)
at eval (blocks.ts:296)
at Module../shared/blocks.ts (48ba4b417edc794a158b.worker.js:311)
at __webpack_require__ (48ba4b417edc794a158b.worker.js:29)
at Module.eval (WorldChunk.ts:12)
at eval (WorldChunk.ts?c4f7:22)
at Module../lib/Data/WorldChunk.ts (48ba4b417edc794a158b.worker.js:115)
at __webpack_require__ (48ba4b417edc794a158b.worker.js:29)
at Module.eval (WorldChunkReader.worker.ts?024a:1)
at eval (WorldChunkReader.worker.ts?024a:21)
To Reproduce
- Configure
worker-loader
like so innext.config.js
:
config.module.rules.unshift({
test: /\.worker\.(js|ts|tsx)$/,
loader: "worker-loader",
options: {
name: "static/[hash].worker.js",
publicPath: "/_next/",
},
});
// Overcome webpack referencing `window` in chunks
config.output.globalObject = "self";
- Load a worker
- See error
Expected behavior
No error, workers load successfully as in Next 9.3
Screenshots
System information
- OS: macOS
- Browser (if applies) Chrome
- Version of Next.js: 9.4.0
- Version of Node.js: 13.12.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:7 (2 by maintainers)
Top Results From Across the Web
ReferenceError: $RefreshReg$ is not defined - Stack Overflow
In my case, this error was happening when overwriting Webpack's mode option. After removing the line below I stopped receiving the error.
Read more >Web Workers API - W3Schools
A web worker is a JavaScript running in the background, without affecting the performance of the page. What is a Web Worker? When...
Read more >Threading the web with module workers - web.dev
Module workers make it easy to unblock the main thread by moving expensive code to a background thread while keeping the ergonomic and ......
Read more >Web Worker in Javascript for beginners ... - YouTube
Web Worker in Javascript for beginnersWEB WORKER 2021Web worker was introduced with HTML5 and it is a way to use multithreading in browsers....
Read more >Understanding and Using Web Workers - CODE Magazine
Event-Based Communication. Events are how your application and the Web Worker script communicate with each other. When you start a Web Worker, ...
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 FreeTop 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
Top GitHub Comments
@Timer here you go: https://github.com/Jarred-Sumner/repro-refreshregistry
I began seeing this same issue when I upgraded to next 9.4 from 9.3. It’s only impacting dev for me, when I deployed it to vercel, the error was not there