workers-sdk: 🐛 BUG: "Cannot convert object to primitive value" at publish time

What version of Wrangler are you using?

2.1.13

What operating system are you using?

Mac M1

Describe the Bug

Pushing my nuxt 3 website from local and github actions, I get the following error:

❯ yarn workspace @hack/hack.com deploy
 ⛅️ wrangler 2.1.13 
--------------------
Running custom build: NITRO_PRESET=cloudflare yarn nuxt build
Nuxi 3.0.0-rc.13-27779809.b010e3e                                                                                                  10:47:01
Nuxt 3.0.0-rc.13-27779809.b010e3e with Nitro 0.6.1-27778247.5a75f37                                                                10:47:01
WILL SETUP TAILWIND!!!                                                                                                             10:47:01
SETUP COMPLETE!!!                                                                                                                  10:47:01
ℹ Using default Tailwind CSS file from runtime/tailwind.css                                                       nuxt:tailwindcss 10:47:01
ℹ Client built in 1840ms                                                                                                           10:47:04
ℹ Building server...                                                                                                               10:47:04
✔ Server built in 588ms                                                                                                            10:47:05
✔ Generated public .output/public                                                                                            nitro 10:47:05
ℹ Building Nitro Server (preset: cloudflare)                                                                                 nitro 10:47:05
✔ Nitro server built                                                                                                         nitro 10:47:14
  └─ .output/server/index.mjs (1.26 MB) (340 kB gzip)
Σ Total size: 1.26 MB (340 kB gzip)
✔ You can preview this build using npx wrangler dev .output/server/index.mjs --site .output/public --local                   nitro 10:47:14
✔ You can deploy this build using npx wrangler publish                                                                       nitro 10:47:14

Reading _nuxt/bg.66f7b96c.svg...
Skipping - already uploaded.
Reading _nuxt/entry.16f5fac9.css...
Skipping - already uploaded.
Reading _nuxt/entry.20485e58.js...
Skipping - already uploaded.
Reading _nuxt/error-404.4cf85664.css...
Skipping - already uploaded.
Reading _nuxt/error-404.8b61b839.js...
Skipping - already uploaded.
Reading _nuxt/error-500.0840c7e1.js...
Skipping - already uploaded.
Reading _nuxt/error-500.bddb6786.css...
Skipping - already uploaded.
Reading _nuxt/error-component.942be2ad.js...
Skipping - already uploaded.
Reading _nuxt/index.d4bbdb4a.css...
Skipping - already uploaded.
Reading _nuxt/index.d7d5c4a0.js...
Skipping - already uploaded.
↗️  Done syncing assets
Total Upload: 1707.68 KiB / gzip: 381.96 KiB

✘ [ERROR] A request to the Cloudflare API (/accounts/cb2a436242e067a239fef867877ec6fd/workers/scripts/hack) failed.

  Uncaught TypeError: Cannot convert object to primitive value
    at worker.js:22345:471
    at worker.js:32316:4
    at worker.js:32317:3
   [code: 10021]

  If you think this is a bug, please open an issue at:
  https://github.com/cloudflare/wrangler2/issues/new/choose

It’s kind of weird because I have two nuxt projects in the same monorepo and only this one gives this error. The only difference between these two projects is the one with the problem I’m using Firebase Firestore .

Running locally + some console.log’s

/private/var/folders/q7/7xksn2wx0dj486bq5yvsjzc00000gn/T/tmp-53310-q0l6XrQczK3c/index.js:22347
    const defaultResponseHeaders = { [GRPC_ACCEPT_ENCODING_HEADER]: "identity,deflate,gzip", [GRPC_ENCODING_HEADER]: "identity", [http2$1.constants.HTTP2_HEADER_STATUS]: http2$1.constants.HTTP_STATUS_OK, [http2$1.constants.HTTP2_HEADER_CONTENT_TYPE]: "application/grpc+proto" }, defaultResponseOptions = { waitForTrailers: true };
                                                                                                                                                    ^

TypeError: Cannot convert object to primitive value

Logging the http2 in the setup phase

-----------------------------------------
http2 {                                                                                                                            14:15:28
  connect: [Function: connect],
  constants: {
    NGHTTP2_ERR_FRAME_SIZE_ERROR: -522,
    ...
}
http2.constants {                                                                                                                  14:15:28
  NGHTTP2_ERR_FRAME_SIZE_ERROR: -522,
  NGHTTP2_SESSION_SERVER: 0,
  ...
}
http2.constants.HTTP2_HEADER_STATUS :status                                                                                        14:15:28
http2.constants.HTTP2_HEADER_CONTENT_TYPE content-type                                                                             14:15:28
-----------------------------------------    

Logging the http2 in the “execution phase”

----------------------------------------
http2 [Function: fn]
http2.constants [Function: fn]
http2.constants.HTTP2_HEADER_STATUS [Function: fn]
http2.constants.HTTP2_HEADER_CONTENT_TYPE [Function: fn]
-----------------------------------------

This difference is causing the problem when using these values as dynamic map key.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (3 by maintainers)

Most upvoted comments

Exact same issue here, using Firebase Admin too, Nuxt 3, Nitro.

@brendonmatos Interesting to close this issue. Can you give a bit of context how you solved the issue / why it is no longer an issue? Thank you.

Hi There, I think I’m having the same issue with a Nuxt 3 build to Cloudflare Pages Functions.

I’ve created a StackBlitz with a minimal reproduction: https://stackblitz.com/edit/nuxt-wrangler-firebase-bug?file=server/middleware/admin.ts

My environment details
node -v
v16.18.1
yarn wrangler -v
 ⛅️ wrangler 2.4.4 
yarn nuxt -v
Nuxi 3.0.0    

Firebase uses -> grpc-js, that uses -> http2

It seems that the problem lies in the failure or lack of implementation of this http2 polyfill in workers runtime.

I am also experincing this issue. Also with Nuxt 3, Nitro, Firebase, Cloudflare Workers. I am not using nuxt-security. Will update if I find a workaround.

Hi everyone. Any progress on this bug? I am also building a web application using Firebase. Initially, I created it in SPA, but because the OGP images were not loading properly in Twitter and other social networking sites, I removed the ssr:false in nuxt.config.ts and changed it to SSR.

The npx nuxi build completed successfully. However, when I run npx wrangler pages dev dist/, I get this error. The preset for nitro was cloudflare-pages.

Environment Node: v18.16.0 Nuxt: v3.5.3 Nitro: v2.4.1 wrangler: v3.1.1

After some troubleshooting, I’ve figured the nuxt-security module was causing those errors on my non-string API endpoints. After disabling it, all works fine.

This is still related to Cloudflare since the nuxt-security module works fine on Vercel or Netlify.

This is very interesting. I would be interested in chatting more on this, are you on the Cloudflare Discord?