cli icon indicating copy to clipboard operation
cli copied to clipboard

JSONHTTPError when deploying Next.js app inside Nx workspace

Open AlanAcDz opened this issue 3 years ago • 9 comments

Describe the bug

I'm trying to deploy a next.js app that's inside a Nx workspace using netlify-cli. I have configured the build settings as show below in the netlify.toml file and in the netlify UI. I have logged in using the cli and I'm setting the site ID as an environment variable in my terminal.

The app builds without problem including the @netlify/plugin-nextjs output, the issue begins at the upload stage. After 20 minutes (at least) it just errors out with this message:

{
  "name": "JSONHTTPError",
  "status": 500,
  "json": {
    "status": 500,
    "error": "Internal Server Error"
  }
}

I have tried running the deploy command as:

npx netlify deploy --prod --build

as well as:

npx netlify build
npx netlify deploy --prod

with no luck.

I have also tried doing the same with a clean nx workspace with a next app, here's the repo. The error is the same and it takes the same amount of time

Here's the full log with the DEBUG=* env variable in my original project: error.txt

Steps to reproduce

  1. git clone https://github.com/AlanAcDz/nx-next-test.git
  2. npm install (it includes netlify-cli as a devDependency)
  3. npx netlify login
  4. set site ID as environment variable
  5. npx netlify deploy --build --prod
  6. *go get a coffee and a snack cause it takes a while
  7. the cli errors out

Configuration

[build] command = "nx build next-test" publish = "dist/apps/next-test/.next"

[[plugins]] package = "@netlify/plugin-nextjs"

Environment

System:
    OS: Windows 10 10.0.22000
    CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics
    Memory: 4.76 GB / 15.36 GB
  Binaries:
    Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.9.0 - C:\Program Files\nodejs\npm.CMD
npmPackages:
    netlify-cli: ^10.2.0

AlanAcDz avatar May 05 '22 01:05 AlanAcDz

Forgot to mention, this issue is found only using the netlify-cli. If I activate github builds in the UI there is no problem whatsoever using the same configuration, the app builds and deploys just fine

AlanAcDz avatar May 05 '22 01:05 AlanAcDz

Seeing the same thing, started happening this morning with a build triggered by content changes in the CMS.

2022-05-13T09:15:49.0557514Z Deploying to main site URL...
2022-05-13T09:15:49.6208989Z - Hashing files...
2022-05-13T09:15:49.6238898Z - Looking for a functions cache...
2022-05-13T09:15:49.6259193Z √ Deploying functions from cache (use --skip-functions-cache to override)
2022-05-13T09:15:50.5900168Z √ Finished hashing 1249 files and 3 functions
2022-05-13T09:15:50.5900729Z - CDN diffing files...
2022-05-13T09:15:52.2079659Z √ CDN requesting 497 files and 2 functions
2022-05-13T09:15:52.2087417Z - Uploading 501 files
2022-05-13T09:38:43.2252409Z  »   Warning: JSONHTTPError:  500
2022-05-13T09:38:43.2253876Z  »   Warning: 
2022-05-13T09:38:43.2255033Z {
2022-05-13T09:38:43.2256173Z   "name": "JSONHTTPError",
2022-05-13T09:38:43.2256582Z   "status": 500,
2022-05-13T09:38:43.2259076Z   "json": {
2022-05-13T09:38:43.2259387Z     "status": 500,
2022-05-13T09:38:43.2260896Z     "error": "Internal Server Error"
2022-05-13T09:38:43.2261306Z   }
2022-05-13T09:38:43.2261547Z }
2022-05-13T09:38:43.2262133Z 
2022-05-13T09:38:53.7609169Z  »   JSONHTTPError: Internal Server Error
2022-05-13T09:38:53.7990365Z error Command failed with exit code 1.

rshackleton avatar May 13 '22 10:05 rshackleton

Update: so I installed latest version of netlify-cli (10.3.3), still does not work but now the error is completely different. I'm attaching the new error, although it seems not to be the full error, my terminal did not keep the whole thing

new-error.txt

AlanAcDz avatar May 28 '22 17:05 AlanAcDz

Update 2: with version 10.4.0 of netlify-cli, it outputs the same error as it was before:

{
  "name": "JSONHTTPError",
  "status": 500,
  "json": {
    "status": 500,
    "error": "Internal Server Error"
  }
}

It's been a whole month since I first opened this issue and yet there has been no acknowledgement of it.

@rshackleton are you still seeing this error too?

AlanAcDz avatar Jun 07 '22 19:06 AlanAcDz

We ended up changing the site to not build as many pages statically to try and workaround the issue, so not we're not but we probably would be if we changed it back.

rshackleton avatar Jun 08 '22 13:06 rshackleton

Update 3: I have tried upgrading to the latest version 10.5.0 and downgrading to version 9.16.7, neither works. This makes me think that the issue might not be within netlify-cli itself and instead be the connection bewteen netlify-cli and netlify servers in this specific situation (nx workspace with nextjs app)

I may continue to post updates every now and then about this issue, at least until it's acknowleged. If someone else encounters this I advice you to use netlify's UI to deploy your nx apps, that one works fine

AlanAcDz avatar Jun 10 '22 00:06 AlanAcDz

This only happens if you have large dependencies and static pages generated. Try limiting it, if you can't, there's no really good option but only publish it using github or other pipeline.

ajereos-circadence avatar Jun 10 '22 05:06 ajereos-circadence

Interesting, I am in fact generating static pages but I don't think 17 of them would cause the issue and none of them is more than 5kb. Either way it seems really strange that only netlify-cli has this issue

AlanAcDz avatar Jun 11 '22 00:06 AlanAcDz

We've changed our handling of monorepos in v16+ . Is this issue still occurring?

sarahetter avatar Sep 14 '23 20:09 sarahetter