skip to Main Content

I’m completely at a loss. I have a React app I’ve been working on for some time and yesterday I found I was unable to build it. I keep getting the following error on ‘npm run build’:
Creating an optimized production build…
Failed to compile.

Unexpected end of JSON input

Steps I have taken:

  • npm cache clean –force
  • rm -rf node_modules package-lock.json
  • rm -rf ~/.npm
  • npm install
  • checked all .json formatting
  • tested the package.json file with node -e
  • Used yarn to build (same error)

I have created a new React project and was able to build without errors.
I have taken all the packages from package.json in my problem project, pasted them into a new project and was able to build without error.

I’m not sure what to do now other than completely rebuild my project piece by piece.

2

Answers


  1. I’m having the same issue for my react application since today and i think its a bug in the new NodeJs version. I fixed it by downgrading my version from 23.2.0 (newest at this time) to the LTS 22.11.0. Hope this will do the trick for you aswell.

    Login or Signup to reply.
  2. I setup my Docker file with node version:22-alpine3.19. Downgrading the NodeJS version works.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search