-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
In web worker, typeof window === 'undefined' is falsely bundled to true
#61858
Comments
@kdy1 Is it a swc issue? |
No, it's not |
And this is duplicate |
Ah, sorry for that. #60644 (I think the issue may be incorrect because window should be undefined in web worker) |
Also duplicates #61740 I think both #60644 and #61740 does not address the issue correctly. |
I highly suspect #59569 is the root cause. See also: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers#web_workers_api |
I'm using web worker and loaded worker code depends on other 3rd party library which checks window object.
|
We should disable the swc optimizer for the node_modules in app browser layer. I filled a PR for fixing it |
Thanks and happy new year :) |
) ### What Disable swc transform optimizer for node_modules in browser layer of app router bundles Fixes #61858 Fixes #60644 Fixes #60920 Fixes #61740 Closes NEXT-2418 ### Why In browser there could be not only one runtime, it could have both js worker and browser. In js worker the `typeof window` is not as same as in browser, so disabling the swc optimizer which will replace the code. Leave the condition as it as.
) Disable swc transform optimizer for node_modules in browser layer of app router bundles Fixes #61858 Fixes #60644 Fixes #60920 Fixes #61740 Closes NEXT-2418 In browser there could be not only one runtime, it could have both js worker and browser. In js worker the `typeof window` is not as same as in browser, so disabling the swc optimizer which will replace the code. Leave the condition as it as.
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://github.com/yf-yang/next-webworker-bug
To Reproduce
Current vs. Expected behavior
Expected:
Web worker started, then debugjs can log a message "worker started" (console log level should be "verbose")
Current:
Error: Uncaught ReferenceError: window is not defined
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64 Binaries: Node: 20.9.0 npm: 10.1.0 Yarn: 1.22.19 pnpm: 8.14.3 Relevant Packages: next: 14.1.1-canary.45 // Latest available version is detected (14.1.1-canary.45). eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: N/A Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
SWC transpilation
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
The error is this line in
debug.js
:https://github.com/debug-js/debug/blob/f66cb2d9f729e1a592e72d3698e3b75329d75a25/src/browser.js#L119-L121
In the bundled output file
.next/static/chunks/_app-pages-browser_app_worker_js.js
, this line is transpiled toThe bundled output is wrong, because in web worker,
window
does not exist.NOTE: This bug does not exist in next@13.5.6
NEXT-2418
The text was updated successfully, but these errors were encountered: