Skip to content
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

Worker not compiling correctly, window is undefined in files after canary 14.0.5-canary.19 #60644

Closed
1 task done
joacub opened this issue Jan 14, 2024 · 9 comments · Fixed by #62051
Closed
1 task done
Labels
bug Issue was opened via the bug report template. locked

Comments

@joacub
Copy link

joacub commented Jan 14, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/trusting-glade-g3l38y?file=%2Fapp%2Fpage.tsx%3A7%2C1

To Reproduce

pnpm install
pnpm dev

show the console and see the window is undefined

Current vs. Expected behavior

window var is undefined and should be defined as this is in the browser context

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

after any canary 14.0.5-canary.19

Which area(s) are affected? (Select all that apply)

App Router, SWC transpilation

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

canary 14.0.5-canary.19 works perfectly

@joacub joacub added the bug Issue was opened via the bug report template. label Jan 14, 2024
@github-actions github-actions bot added the SWC Related to minification/transpilation in Next.js. label Jan 14, 2024
@joacub joacub changed the title Worker not compiling correctly, window is undefined in react files after canary 14.0.5-canary.19 Worker not compiling correctly, window is undefined in files after canary 14.0.5-canary.19 Jan 15, 2024
@joacub
Copy link
Author

joacub commented Jan 15, 2024

some one checking on this ? is being a blocker to update after .19 canary

@joacub
Copy link
Author

joacub commented Jan 16, 2024

plesaee some one can take care of this, this is a blocker. nextjs cant be used any more if you are using workers.

@joacub
Copy link
Author

joacub commented Jan 17, 2024

related:
#59603

@joacub
Copy link
Author

joacub commented Jan 17, 2024

@yf-yang you close something that still happening and is related to this

@kdy1
Copy link
Member

kdy1 commented Jan 30, 2024

Problematic release: https://github.com/vercel/next.js/releases/tag/v14.0.5-canary.20

@kdy1 kdy1 added the SWC Related to minification/transpilation in Next.js. label Jan 30, 2024
@huozhi huozhi removed the SWC Related to minification/transpilation in Next.js. label Jan 30, 2024
@s0-david
Copy link

s0-david commented Feb 7, 2024

Doesn't seem to work on 14.1.1-canary.42 as well

@yf-yang
Copy link

yf-yang commented Feb 9, 2024

Isn't it a correct behavior?
https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers#web_workers_api
If I got it right, in web worker, only self is available.

workers run in another global context that is different from the current window. Thus, using the window shortcut to get the current global scope (instead of self) within a Worker will return an error.

@joacub
Copy link
Author

joacub commented Feb 10, 2024

Isn't it a correct behavior? https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers#web_workers_api If I got it right, in web worker, only self is available.

workers run in another global context that is different from the current window. Thus, using the window shortcut to get the current global scope (instead of self) within a Worker will return an error.

not it is not, this was working before perfeclty

@huozhi huozhi closed this as completed in cfedc52 Feb 14, 2024
huozhi added a commit that referenced this issue Feb 28, 2024
)

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.
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants