-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Import @apollo/client/utilities/globals
wherever __DEV__
is used
#8720
Conversation
b64e205
to
2b3337a
Compare
2b3337a
to
fa3a70a
Compare
I can confirm this PR fixes the reproduction in #8674. |
class Transformer { | ||
absolutePaths = new Set<string>(); |
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 turned the functions in this file into a utility Transformer
class so we can collect absolutePaths
more easily (in the normalizeId
method). All the existing logic should otherwise be the same.
@roderik The |
Hey folks, I would like to say that this version isn't compatible with IE11 as opposed to 3.4.8. I see in my production build using const & let and this one is issue (3.4.10) : const safeGlobal = (
maybe(function() { return globalThis }) ||
maybe(function() { return window }) ||
maybe(function() { return self }) ||
maybe(function() { return global }) ||
maybe(function() { return Function("return this")() })
);
let needToRemove = false; instead of 3.4.8: var safeGlobal = (
maybe(function() { return globalThis }) ||
maybe(function() { return window }) ||
maybe(function() { return self }) ||
maybe(function() { return global }) ||
maybe(function() { return Function("return this")() })
);
var needToRemove = false; |
@shevchenkonik Thanks for that PR! Fixed in |
I hoped PR #8689 would put a stop to
ReferenceError: __DEV__ is not defined
errors, but issue #8674 demonstrates it's not enough to import the polyfill in entry point@apollo/client/**/index.js
modules, because that still allows some bundlers to tree-shake or reorder dependencies in a way that leads to__DEV__
being used before it has been polyfilled.This PR turns the
src/utilities/globals/
directory into a new nested entry point,@apollo/client/utilities/globals
, which can be imported by itself (independently from the rest of@apollo/client/utilities
), and polyfills__DEV__
the first time it's imported. This module now gets imported in every module that uses__DEV__
, rather than just at the entry points. Although this is a bit of a chore, it seems to be more robust, and it's programmatically enforced at build time. Also,@apollo/client/utilities/globals/package.json
explicitly says"sideEffects": true
, which should hopefully be a clear signal to tree-shaking bundlers to leave this code intact.I threw out the
config/checkDEV.ts
script and instead put the enforcement logic inconfig/resolveModuleIds.ts
, since it's already responsible for parsing files and resolving the modules identifiers they import. Specifically, this logic enforces that anydist/**/*.js
file that ends up using__DEV__
also imports the@apollo/client/utilities/globals
entry point (typically using a relative path like../../utilities/globals
).Fixed issues:
ReferenceError: __DEV__ is not defined
after update to3.4.5
withNext.js
app #8674 (comment)