-
Notifications
You must be signed in to change notification settings - Fork 27.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web Workers are broken in Next.js 11 #26152
Comments
Seeing this too. |
I'm facing similar issues with Web Workers #26144 |
I'm affected too. Would be great to have some regression tests on at least a few of the examples. |
It does work in production build, but not in dev mode. module.exports = {
webpack: (config, { dev }) => {
if (dev) {
config.optimization.splitChunks = false;
}
return config;
},
}; |
@paescuj I tried to build and the build went through, the issue is in dev environment only. |
I can confirm @paescuj's solution works 👍 ! |
I tried this out, but it fails if the Worker uses importScript or require. And yes, disabling splitChunks was my immediate dirty fix as well, sadly not something I can do in a fairly large production codebase. Thanks for the tip though, I'm sure it'll help others coming here! |
Sounds similar to #25484
While it's indeed very dirty, it should not affect the production build. (
You're welcome! 😃 |
Interesting, this didn't happen to me on 10.2.3, but only happens on 11. |
Indeed very interesting! Sounds like a slightly different issue, though. |
Same here! Can't upgrade until these issues are resolved, and I'm excited to try out some of the new features. |
Yeah, we stuck at the earlier version of Next and Webpack 4. Was trying out to migrate over to Next 11, among few other things, WebWorker is a real deal-breaker. The DX seems better, we see much faster interaction on server, hope it gets solved soon |
Can you provide a reproduction? Just checked the example and it runs fine, even with Edits made:
// This is a module worker, so we can use imports (in the browser too!)
import pi from "./utils/pi";
self.importScripts("/foo.js");
addEventListener("message", (event) => {
postMessage(pi(event.data));
});
Tried in both dev and prod. |
Figured out a way to reproduce it, has nothing to do with Reproduction: // This is a module worker, so we can use imports (in the browser too!)
import pi from "./utils/pi";
// Importing a large (huge) library
import faker from 'faker'
console.log(faker)
self.importScripts("/foo.js");
addEventListener("message", (event) => {
postMessage(pi(event.data));
}); |
I see, that actually makes sense! Thanks a lot @timneutkens! 👍 Should also fix #19865 for me. |
Updates the hotUpdateChunk to include `[runtime]` for web workers support. Fixes #26152 Fixes #19865 Fixes #26144 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. ## Documentation / Examples - [ ] Make sure the linting passes
Updates the hotUpdateChunk to include `[runtime]` for web workers support. Fixes vercel#26152 Fixes vercel#19865 Fixes vercel#26144 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. ## Documentation / Examples - [ ] Make sure the linting passes
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
11
What version of Node.js are you using?
v14.16.0
What browser are you using?
Chrome
What operating system are you using?
Windows
How are you deploying your application?
Vercel
Describe the Bug
WebWorker behavior with Next.js 11 is highly volatile with several different errors occurring when importing them. ImportScripts also fails inside the workers. The project as-is worked fine with Next.js 10.2.3.
Expected Behavior
WebWorker works as expected.
To Reproduce
The default example for Web Workers is broken as well, shows the same issues. The importScripts can be reproduced by adding the importScripts code in the worker.
The text was updated successfully, but these errors were encountered: