reactjs - React Build Error - Unexpected end of JSON input - Stack Overflow

I'm completely at a loss. I have a React app I've been working on for some time and yesterday

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.

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.

Share Improve this question asked Nov 18, 2024 at 22:13 C PaynterC Paynter 911 silver badge7 bronze badges 1
  • I am not sure specifically what the problem is but I can tell you the approach I use to find the problem in these kind of situations. If you used git you can make a separate branch and start reverting commit by commit and seeing which commit changed the build from working to non working, it might seem like this will take a while but it will give you a deeper understanding in the end of the framework you are using. Good luck! – Lars Vonk Commented Nov 18, 2024 at 23:06
Add a comment  | 

3 Answers 3

Reset to default 17

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.

As @Max mentioned it's a bug in latest nodejs.

We just changed the first line of the pipeline configuration (bitbucket-pipelines.yml) from image: node to image: node:lts and the problem was solved.

I setup my Docker file with node version:22-alpine3.19. Downgrading the NodeJS version works.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745591037a4634832.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信