nuxt-modules / apollo

Nuxt.js module to use Vue-Apollo. The Apollo integration for GraphQL.
https://apollo.nuxtjs.org
MIT License
956 stars 198 forks source link

`nuxi start` request error and out of memory on Nuxt 2 Bridge #435

Closed thisismydesign closed 2 years ago

thisismydesign commented 2 years ago

First off, https://cmty.app/nuxt/issues/new?repo=apollo-module is not available to create issues :(

I'm trying to use apollo-module with Nuxt 2 Bridge. It works fine with nuxi dev and with the old nuxt tooling as well. However, building and starting with the new tooling and then opening a page results in the following error:

[nuxt] [request error] external_universal_cookie_default.a is not a constructor
  at apollo_module (./server/chunks/app/server.mjs:42477:24)  
  at createApp (./server/chunks/app/server.mjs:44130:16)  
  at async __webpack_exports__.default (./server/chunks/app/server.mjs:44243:12)  
  at async Object.renderToString (./server/chunks/handlers/renderer.mjs:180:19)  
  at async ./server/chunks/handlers/renderer.mjs:638:20  
  at async ./server/node_modules/h3/dist/index.mjs:592:19  
  at async Server.nodeHandler (./server/node_modules/h3/dist/index.mjs:538:7)

The page load hangs and eventually the server runs out of memory: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory.

My setup:

  apollo: {
    clientConfigs: {
      default: {
        httpEndpoint: 'http://localhost:3001/graphql',
      },
    },
  },
"@nuxtjs/apollo": "4.0.1-rc.4",
"nuxt-edge": "2.16.0-27616340.013f051b",
"@nuxt/bridge": "npm:@nuxt/bridge-edge",

Explicitly installing h3@0.7.15 produces a different error but both look very similar.

[nuxt] [request error] external_universal_cookie_default.a is not a constructor
  at apollo_module (./server/chunks/app/server.mjs:42476:24)  
  at createApp (./server/chunks/app/server.mjs:44129:16)  
  at async __webpack_exports__.default (./server/chunks/app/server.mjs:44242:12)  
  at async Object.renderToString (./server/chunks/handlers/renderer.mjs:179:19)  
  at async ./server/chunks/handlers/renderer.mjs:637:20  
  at async ./server/chunks/nitro/node-server.mjs:411:19  
  at async Server.nodeHandler (./server/chunks/nitro/node-server.mjs:357:7)

A similar error in the auth-module was resolved by transpiling a specific dependency (https://github.com/nuxt-community/auth-module/issues/1519#issuecomment-1242162472). I tried transpiling both h3 and nitropack (and various other dependencies) as well as using different versions but no luck.

thisismydesign commented 2 years ago

Well, yep, needed to transpile universal-cookie which I "figured out" in my desperation by searching "cookie" in yarn.lock (hence external_universal_cookie_default).