question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: __DEV__ is not defined using @apollo/client in Next.js _middleware after upgrading to Node@16

See original GitHub issue

Intended outcome: Call auth query with apollo client in Next.js _middleware via vercel Edge Function using Node@16

Actual outcome: When deployed to vercel I get the following error:

ReferenceError: __DEV__ is not defined
    at node_modules/.pnpm/@apollo+client@3.6.4_cd52a2e2ff1958b4ef767d2bf22947af/node_modules/@apollo/client/utilities/globals/index.js:5:0
    at node_modules/.pnpm/@apollo+client@3.6.4_cd52a2e2ff1958b4ef767d2bf22947af/node_modules/@apollo/client/utilities/globals/index.js:12:0
    at webpack/bootstrap:21:0
    at .:11:18
    at webpack/bootstrap:21:0
    at node_modules/.pnpm/react@17.0.2/node_modules/react/index.js:4:2
    at node_modules/.pnpm/react@17.0.2/node_modules/react/index.js:4:2
    at webpack/runtime/jsonp chunk loading:34:0

I tried updating to the latest version of React, Next.js, GraphQL and Apollo Client, but got the same error. I found a few issues around React 18, so downgraded back to 17.

How to reproduce the issue:

  • Create Apollo client instance in Next.js ./pages/_middleware.ts
  • Pass any GraphQL query
  • Deploy app to Vercel
  • View logs in Functions tab after trying to access the preview URL

Versions

  System:
    OS: macOS 11.6.5
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  Browsers:
    Chrome: 100.0.4896.75
    Firefox: 92.0.1
    Safari: 15.4
  npmPackages:
    @apollo/client: ^3.1.4 => 3.6.4
    storybook-addon-apollo-client: ^4.0.9 => 4.0.11

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:7
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
zsotyooocommented, Sep 14, 2022

👋 The same thing happens on Nuxt 3 (production build only). It probably has to do with SSR.

3reactions
websitevirtuosocommented, Oct 9, 2022

I have the same error when implementing vite-ssg In my vuejs 3 project image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started With Apollo Client in Next.js
Using Apollo Client for statically rendered page data. Before we can fetch data from the API, we have to set up our page....
Read more >
Next.js: document is not defined - Stack Overflow
I think, in server rendering mode, the document is undefined. You should be able to use it inside class lifecycle methods or useEffect...
Read more >
what does uuid do in node Code Example - Javascript - Code Grepper
const { v4: uuidv4 } = require("uuid"); import { v4 as uuid } from "uuid";
Read more >
Fixing Next js "ReferenceError: document is not defined"
I came across this error while learning next js and I couldn't understand what I did wrong. The error... Tagged with nextjs, react....
Read more >
@expo/dev-tools | Yarn - Package Manager
Changelog. This is the log of notable changes to Expo CLI and related packages. main. Breaking changes. New features. Chores.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found