-
-
Notifications
You must be signed in to change notification settings - Fork 449
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
(babel) - Fix ESM support by adding typeof process check #827
Conversation
🦋 Changeset is good to goLatest commit: 7fcfc02 We got this. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This is awesome @JoviDeCroock! Really glad to see we're adding in esmodule support. One thing worth emphasizing is that we don't currently have a way of switching between prod / dev builds when using esmodules (not necessarily for optimization purposes but useful for removing developer warnings and prompts). As it stands right now, we default to dev for esmodule which IMHO makes sense. If there's some kind of esmodule standard for flagging the environment the user is working in, we could definitely support that in the future 👍 Super basic example of how someone people might be doing this when deploying
|
Great work @JoviDeCroock 🥳 and yes.. Andy raises a good point. There currently isn't a there isn't any kind of esmodule standard for flagging the environment the user is working in unfortunately. This issue has plagued a few other repos and prevented them becoming fully browser esm compatible like what is being proposed here. Most of the research I have done into this issue is documented in this PR on graphql-js itself graphql/graphql-js#2409 which was the last piece in this puzzle graphql/graphql-js#2277. Perhaps we should consider speccing out what a standard for this could look like! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we’re only missing a changeset here 👍
@@ -0,0 +1,38 @@ | |||
const checkForTypeCheck = (node) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo in the filename here: compatability
=> compatibility
Otherwise only the changeset is missing, but I suppose we can just patch
bump everything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been trying to test some stuff and it seems to work but we haven't got sandboxes for everything 😅 I think this code can't actually negatively impact any places judging from the astexplorer though. If anyone comes up with an edge case please throw it at me.
I'll add the changesets later
This looks like a neat addition! Does it also handle a |
@amyboyd yes it does but for urql doesn't make much of a difference because commonly in bundlers the This optimization is commonly used in
In libraries there probably won't be a case for |
OK, I think I follow. With lines like 144 here, will the |
It shouldn't be a hard requirement, I do it because specifying the env isn't as standard in for instance Because we'd bail out when "production" === "production" for the case where there's no env supplied this will never bail and produce those errors in prod. |
The only case here that's uncovered is that it's not transpiling |
Temporarily closing this until we have a solid solution for ESM dev-checks that compile away |
Add a transform that gets rid of all the
process.env.NODE_ENV !== 'production'
checks and transforms them intotypeof process !== 'undefined' && process.env.NODE_ENV !== 'production'
.This is an issue we initially faced in
devtools
where we tried to introduce conditionalsprocess?.env?.NODE_ENV
which will result in the same esm-incompatability where the global isn't correctly referenced.I've tested and this check is also correctly DCE'd by
terser
andclosure
.Try it out
See it in action