-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
Webpack 5 Undefined Builtin Web Worker on Production Build for with-web-worker #22813
Comments
I've managed to get around this by looking at webpack's proposals, namely:
|
Great tip! Here is the complete next.config.js for the workaround: module.exports = {
future: {
webpack5: true,
},
webpack: (config, { isServer, dev }) => {
config.output.chunkFilename = isServer
? `${dev ? "[name]" : "[name].[fullhash]"}.js`
: `static/chunks/${dev ? "[name]" : "[name].[fullhash]"}.js`;
return config;
},
}; Interestingly the console logs an error with this approach:
But I haven't noticed what this effects yet. I will continue to test this workaround. Also if I'm reading that issue correctly, the bug of |
The fact that webpack says it's solved did confuse me a bit as well, however i think they had some back and forth on it, so not sure what happened there. As for
That one is interesting, not sure if you tracked it down, it is the result of a 'use strict' statement in a compiled file, the file I believe represents the compiled worker. Excerpt from it:
If you were to delete that 'use strict' from .next/static/chunks/< worker file name >.js the error would go away. I would assume this has something to do with webpack, but it is only a guess. I can't tell if it's causing any harm yet. |
I've not yet tracked down the solution to:
The next.js/packages/next/build/webpack-config.ts Line 869 in b267635
So far I've yet to notice detrimental effects from this error. The only thing that it has an impact on is the Lighthouse score, which doesn't like errors written to the console. Tested on next.js 10.0.9 to see if that had an impact -- it does not |
Adding Edit: That worked for about 5 minutes, not sure why it stopped working. |
Next.js 10.1 resolves:
So no more console errors 🎉 The following workaround is still needed to avoid undefined references, however: module.exports = {
future: {
webpack5: true,
},
webpack: (config, { isServer, dev }) => {
config.output.chunkFilename = isServer
? `${dev ? "[name]" : "[name].[fullhash]"}.js`
: `static/chunks/${dev ? "[name]" : "[name].[fullhash]"}.js`;
return config;
},
}; |
Do I still need to use this workaround with Next 10.2.3? |
Seems like the workaround is no longer required in Next.js 11. |
Excellent, I verified that the example and my own web worker app functions without the workaround in next 11. 🎉 Closing the issue. |
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 example does this report relate to?
with-web-worker
What version of Next.js are you using?
10.0.6 -> 10.0.8
What version of Node.js are you using?
v14.16
What browser are you using?
N/A
What operating system are you using?
Ubuntu 20.04
How are you deploying your application?
both (next start) and (next export) are effected
Describe the Bug
In production mode, an app that uses webpack 5's builtin support for web worker will try to load the web worker js from (emphasis mine):
This will fail due to the file not existing even though webpack will successfully output the chunk:
This does not effect development. The web worker loads and executes fine in development, though the worker does log the following error:
Expected Behavior
For the web worker to be bundled appropriately for production builds
To Reproduce
Take the web worker example:
And apply the following changes
Replace next.config.js with:
pages/index.js
Optionally remove
worker-loader
dependency as webpack 5 has web worker support builtinExecute:
npm run build && npm run start
Open the page and the console will immediately log the error. This effects
next export
as well.I did try and see if #21977 fixes the issue (rebasing it off v10.0.8 in the process), but it did not.
This is the continuation of the following discussion: #22096
EDIT: current debugging status:
"undefined"
key 🤔The text was updated successfully, but these errors were encountered: