Skip to content
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

Jitsu causing an internal server error with Next JS deployed on cloudflare #1118

Closed
Ali-hd opened this issue Aug 19, 2024 · 7 comments
Closed
Assignees

Comments

@Ali-hd
Copy link

Ali-hd commented Aug 19, 2024

Summary

Hi,

I am facing an issue using Jitsu with Next js. I deployed my app to cloudflare pages but the following happens

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

System configuration and versions

next: v14.2.5
@jitsu/jitsu-react: v1.9.8
@cloudflare/next-on-pages: v1.13.2

@Ali-hd Ali-hd changed the title Jitsu causing an internal server error with Next JS Jitsu causing an internal server error with Next JS deployed on cloudflare Aug 19, 2024
@vklimontovich
Copy link
Contributor

Hi @Ali-hd, have you followed all steps from Cloudflare docs? As far as I see there's not Cloudflare calls in next-config.

If you can work on example a little more and make a npm preview script that starts the app in the dev mode, it would be a huge help for us. Let's see if the issue persists in dev mode and take from there. Unfortunately, we don't have resources to test clouflare pages from ground up at the moment...

@Ali-hd
Copy link
Author

Ali-hd commented Aug 20, 2024

Hi @vklimontovich, the part I didn't add from Cloudflare docs was not needed for my usage.

Our production app uses many packages and everything is working normally. This issue suddenly happened without any change in code, if we rebuild our production it would trigger the issue. We had previously used jitsu with no issues.

This issue doesn't happen locally on a production build when using the same build command, it only happens on Cloudflare.

I deployed it on preview but it's using the same build command as production, when I try to change it the build breaks.

@vklimontovich
Copy link
Contributor

Were you able reproduce the issue with locally? If so, would you mind committing it to your repo?

@Ali-hd
Copy link
Author

Ali-hd commented Aug 20, 2024

No, could not reproduce it locally

@vklimontovich
Copy link
Contributor

Ok, then we need to wait for someone to make the issue reproducible. Meanwhile, here's what I suggest:

  • Follow Cloudflare docs. Maybe, the proper setup will fix the issue
  • Check if the jitsu package was upgraded automatically and pin it to a last working version

Copy link

github-actions bot commented Sep 6, 2024

This issue is stale because it has been open for 30 days with no activity.

Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants