-
Notifications
You must be signed in to change notification settings - Fork 29.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
navigator object breaks projects in v21.0.0 #50269
Comments
i have same problem too, |
This is probably due to #47769 I can reproduce a similar crash with a Next.js app. In my case the problem is with this code (not mine, it's from a dependency): const userAgent = typeof navigator !== "undefined" ? navigator.userAgent : "";
const commandKeyExists = userAgent.includes("Macintosh") || userAgent.includes("iPad") || userAgent.includes("iPhone"); |
/cc @nodejs/tsc I don't know if it was considered before landing the See https://grep.app/search?q=typeof%20navigator%20%21%3D%3D |
#47769 adds |
When we merge PR #43155 it maybe mitigates this issue? |
@targos I don't think anybody raised that objection. Given I was skeptical to begin with to add this, I'm also ok for dropping. |
@targos because of this risk, we made it a semver major. navigator is in the WHATWG minimum recommended API. we can remove it, but eventually we need to implement/add WHATWG recommendations, don't we? |
That's what we always do with new globals. There should be a very good reason to potentially break so many users (and there's not much they can do in this case, since it breaks their dependencies).
why? |
@Ethan-Arrowood @styfle wdyt? |
There is kind of a double-sided problem here:
|
IMHO It was a strategic mistak to add navigator in this minimalistic shape and form. It is not a mvp, as it lacks alot of features. I assume, that when you green light navigator, we could provide PRs to implement navigator with all necessary flags and options in the next couple of days. Detecting jsdom in browser-or-node package is interesting: https://github.com/flexdinesh/browser-or-node/blob/master/src/index.js |
So, what is the solution? |
I think the problem is people check for browser instead of checking for node.js. |
A first step would probably be to add a CLI flag to disable the global, as we have for |
Removing the global isn't the solution. Code that checks for it will just need to update. Sure we can also add a flag to disable it, but I'd think they could do so themselves? node --import 'data:text/javascript,delete globalThis.navigator' app.js |
I wouldn't be so categorical. If the global does more harm than good, removing it, or putting it behind a flag is a reasonable solution. IMO |
I'd say to put it behind a flag, until is mature enough |
@jim-king-2000 What is the line of code your build is erroring on? Can you provide a minimal reproduction? |
I don't know. It is the code of some library.
Sure. But it would take some time. |
Well from @targos Perhaps you can open a separate issue for your Next app, if you can pin down the cause for that one. |
@targos I think this should be brought up to WINTERCG. I don't know the main purpose of adding |
I’m opposed to removing it. I don’t think we should assume that this is our course of action, or reach out to anyone with that assumption until we decide that this is the direction we want to go. |
@mcollina I explicitly raised this specific concern, e.g., in #39540 (comment). I also was highly skeptical of adding
@anonrig I think that's somewhat reasonable. The only relevant specification is the HTML Standard, which Node.js does not claim to implement (besides a small subset of APIs), nor are we obligated to implement any of it. Section 8.9 of the specification defines a navigator as a "user agent (the client)" and later in that section refers specifically to "web browsers". Historically, the word "navigator" was used for early web browsers (i.e., Netscape). Indeed, a spec-compliant implementation of Therefore, I think it's fair for people to assume that software that defines |
The relevant spec for us is https://common-min-api.proposal.wintercg.org/#requirements-for-navigatoruseragent. Deno implements
And so does Bun:
|
Sure, but the WinterCG spec again delegates to the HTML standard (see "Terms defined by reference") for the term "navigator" (i.e., web browser). I am not saying that WinterCG is right or wrong, nor am I saying that following the WinterCG's suggestions is right or wrong. All I am saying is that users are somewhat justified in assuming that a runtime that implements |
Semver majors have breaking changes. That’s what they’re for. In this case adding We also don’t need to create a flag to disable it. That’s already possible today: $ node --print 'navigator'
Navigator {}
$ node --import 'data:text/javascript,delete globalThis.navigator' --print 'navigator'
[eval]:1
navigator
^
ReferenceError: navigator is not defined We could perhaps add a mention of |
@jim-king-2000 Node 21.1.0 is out now. Does it fix your issue? |
Yes. Thanks for the quick fix. |
And I think we could close this issue. |
I have platform implementation in my local node repo. Will provide in an hour a PR. But if tsc decides to delete navigator.. |
@mcollina |
Discussed in the TSC meeting, agreed it no longer needs to be on the agenda. |
was there a consensus on removing navigator, or just that node is no longer breaking things with the addition of navigator.userAgent? |
It was implicitly accepted. See the video to the livestream. It was not explicitly discussed about removing it. |
As far as I can tell from the meeting notes, there was no consensus either way. Only this particular issue is considered to have been resolved. |
From the video i can say that the tsc members agreed on that we should have added userAgent first because it is the most popular attribute and this was a mistake. Now we added it and also there were some citgm changes to detect such a change regarding browser compatibility in the future better. |
I still don't see the value in having navigator but I agree that navigator should have included userAgent when it was added. I wouldn't call that an agreement that node should keep it. |
Any contributor can open a PR to remove If a PR to remove |
The issue there is that it's much more effort to revert the change than it is to keep it, where I have the time to make comments on issues, but I don't have the time to maintain a PR that, admittedly, would be blocked. Kinda meta, but how would removing it work - at least one tsc member believes it should be kept, which means there'd be a stalemate? |
If a question for the TSC is discussed and there isn’t consensus (unanimous agreement) then it goes to a simple majority vote of the TSC. |
Just to confirm - is this an up-to-date link for the Navigator Web API? https://html.spec.whatwg.org/multipage/system-state.html#the-navigator-object It's the link I posted in #50385 too. |
a lot of projects use typescript and the global |
Version
21.0.0
Platform
ubuntu
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
It reproduces every time. No condition.
What is the expected behavior? Why is that the expected behavior?
Build it successfully. Fall back to v20 it works well.
What do you see instead?
Additional information
It is a regression.
The text was updated successfully, but these errors were encountered: