-
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
ReferenceError: __DEV__ is not defined
after update to 3.4.5
with Next.js
app
#8674
Comments
@FlorentD Can you share a stacktrace leading to the |
@benjamn sorry for the delay. With production build and sourcemaps I've got this :
|
Hello @benjamn. I'm not sure if |
@FlorentD Same stack trace? Do you have (could you share) any code that imports from |
Hello @benjamn, I've setup a very tiny NextJS app to reproduce the bug : https://github.com/FlorentD/apollo-client-bug-exemple You can see the built app with the bug ( By adding this import (which does nothing) I crash the app : https://github.com/FlorentD/apollo-client-bug-exemple/blob/d74160c71c1295ecccb2a303ceb957cce10fe97b/apollo/index.js#L2 Hope it helps ! |
Thanks for the reproduction! My hunch is that Parcel is doing some tree-shaking or scope hoisting that eliminates/reorders the code that polyfills We have this Just so I don't leave you stuck without a workaround: if you define |
Also having this issue with webpack and
|
@FlorentD Thanks to your reproduction, I can confirm PR #8720 fixes the problem you were seeing! Please take a look when you have a chance. If everything looks good, those changes will probably get released in Small (possibly obvious) note: in order to verify the fix, I had to delete the |
The problem seems fixed for me by |
Hello @benjamn ! |
Hmm, I just found this issue - this just started happening to me after upgrading to |
Same issue here, the upgrade to |
@oyed @lauraseidler Could either of you provide a small runnable reproduction? |
Yup, 3.4.10 blows up vite. I'll see if I can work up a sandbox for it. |
Same thing here: Vite (latest, |
Hey @benjamn, here's a reproduction: https://github.com/lauraseidler/vite-apollo-3.4.10 - I've had TypeScript in there at first, but removed it now - the problem appears either way. |
@eugene1g Hope it helps.. <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script>
this['__DEV__'] = false
</script>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html> |
Vite users can use a function in vite.config.js and set a define option:
|
@davidbarral That sounds like the best solution ultimately, but I'm still hopeful we can make this work out-of-the-box with no configuration. |
@davidbarral's solution worked for me with this
The relevant parts are that you need to pass a function to |
Yep, I hope so too 😃 |
Using a define DEV in vite unfortunately doesn't work for me. One of my indirect dependencies (npm module
which of course breaks the build:
The workaround with defining DEV in index.html works fine. |
Actually using `checkDEV` by calling it (instead of just re-exporting it) appears to fix the reproduction provided in this comment: #8674 (comment)
Alright, @lauraseidler's reproduction from #8674 (comment) (thanks for that!) seems to be fixed (by #8767), so I encourage everyone using Vite (or having similar problems with other bundlers) to try updating to If #8767 turns out to be the full solution, this regression was due to aggressive tree-shaking by Vite, but was fixable on the Apollo Client side, so you shouldn't need to configure anything to make it work now. |
Confirmed working for us, thanks. |
…and still work on Next.js! :-D |
Based on early feedback, I'm optimistic this is fixed now. Thanks to everyone for surfacing your issues and being patient while we iron out the kinks in this new |
I noticed some strange behaviour around fastRefresh, tracked down to #7952, but this seemed to be fixed already?. Turns out DEV always returns false, so the fastRefresh fix is never applied. We have a micro-frontend architecture, its possible during development that two applications with their own versions of Apollo can be on a page at the same time. Would this cause DEV to be set to false, Im struggling to find the any point where DEV gets set. |
Hi there, I'm still seeing this issue on Next13, using the "old" Next12 middlewares on Vercel. Do you have any workaround for this? Thanks 🙏 |
Intended outcome:
After updating to
3.4.5
, on ourNext.JS@11.1.0
app, we expect that our app launch with any problem.Actual outcome:
On our production bundle (everything works fine on dev mode), we got this message on runtime
ReferenceError: __DEV__ is not defined
. We had the same problem with the3.4.0
, but it has been fixed on3.4.1
following this issue #8557.Something may have changed between
3.4.4
and3.4.5
, and still here on3.4.8
.How to reproduce the issue:
Our repo is private but let me know if you want me to setup a simple exemple with NextJS / Apollo to have some tests. We have this problem on our every nextJS app using
@apollo/client>3.4.4
.Versions
The text was updated successfully, but these errors were encountered: