cloudflare / next-on-pages

CLI to build and develop Next.js apps for Cloudflare Pages
https://www.npmjs.com/package/@cloudflare/next-on-pages
MIT License
1.3k stars 126 forks source link

[🐛 Bug]: Internal Server Error when using Jitsu #862

Open Ali-hd opened 3 months ago

Ali-hd commented 3 months ago

next-on-pages environment related information

Build is successful

Description

There is an error returned on any page that uses Jitsu (either @jitsu/jitsu-react or @jitsu/js). The page returns Internal Server Error with no other error info.

When checking the cloudflare deployment logs, I see two errors messages. This:

  "truncated": false,
  "outcome": "ok",
  "scriptName": "pages-worker--3536470-production",
  "diagnosticsChannelEvents": [],
  "exceptions": [],
  "logs": [
    {
      "message": [
        "Error: An error occurred while evaluating the target edge function (__next-on-pages-dist__/functions/index.func.js)"
      ],
      "level": "error",
      "timestamp": 1724090044141
    }
  ],
  "eventTimestamp": 1724090044139,
  "event": {
    "request": {
      "url": "https://jistu-cloudflare-nextjs-bug-reproduce.pages.dev/",
      "method": "GET",
      "headers": {
        "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
        "accept-encoding": "gzip, br",
        "accept-language": "en-US,en;q=0.9,ar;q=0.8",
        "cache-control": "max-age=0",

Or this

{
  "truncated": false,
  "outcome": "ok",
  "scriptName": "pages-worker--3536470-production",
  "diagnosticsChannelEvents": [],
  "exceptions": [],
  "logs": [
    {
      "message": [
        "TypeError: Cannot read properties of undefined (reading '__global__')"
      ],
      "level": "error",
      "timestamp": 1724090106484
    }
  ],
  "eventTimestamp": 1724090106408,
  "event": {
    "request": {
      "url": "https://jistu-cloudflare-nextjs-bug-reproduce.pages.dev/",
      "method": "GET",
      "headers": {
        "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
        "accept-encoding": "gzip, br",
        "accept-language": "en-US,en;q=0.9,ar;q=0.8",
        "cache-control": "max-age=0",

These errors did not help me identify the cause of the issue. I tried running the code on the server side only flags, but the error still occurred.

I also tried using the App Router, it displayed the page, but I can see a server error 500 in the browser network.

Reproduction

Fresh next js Repo deployed to cloudflare pages with jitsu added https://github.com/Ali-hd/jistu-cloudflare-nextjs-bug-reproduce

You can test it in this url https://jistu-cloudflare-nextjs-bug-reproduce.pages.dev

You can visit the app router page here https://jistu-cloudflare-nextjs-bug-reproduce.pages.dev/todo

I don't think jitsu host and writekey values matter, you can use empty values

Pages Deployment Method

None

Pages Deployment ID

No response

Additional Information

No response

Would you like to help?