9

I am trying to build my react app. But when I run "npm run build", The terminal freezes on "Creating and optimized production build..." and never finish. This is my JSON file. I tried on 16 GB ram also.

I have deleted package lock file and also rebuild the dependencies. But it remains same. There is no specific solution anywhere, if anyone has solution please let me know.

{
  "name": "demoapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.4.1",
    "@emotion/styled": "^11.3.0",
    "@material-ui/core": "^4.12.2",
    "@material-ui/data-grid": "^4.0.0-alpha.33",
    "@material-ui/lab": "^4.0.0-alpha.60",
    "@mui/material": "^5.0.3",
    "@progress/kendo-drawing": "^1.16.0",
    "@progress/kendo-licensing": "^1.2.1",
    "@progress/kendo-react-pdf": "^4.12.0",
    "@progress/kendo-theme-material": "^4.43.0",
    "@progress/kendo-ui": "^2021.3.1109",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "axios": "^0.21.1",
    "bootstrap": "^5.0.2",
    "chart.js": "^3.5.0",
    "dom-to-pdf": "^0.2.2",
    "draft-js": "^0.11.7",
    "draftjs-to-html": "^0.9.1",
    "html-to-draftjs": "^1.5.0",
    "pdf-viewer-reactjs": "^2.2.3",
    "react": "^17.0.2",
    "react-app-polyfill": "^2.0.0",
    "react-chartjs-2": "^3.0.4",
    "react-csv": "^2.0.3",
    "react-dom": "^17.0.2",
    "react-draft-wysiwyg": "^1.14.7",
    "react-hook-form": "^7.10.1",
    "react-icons": "^4.2.0",
    "react-loader": "^2.4.7",
    "react-loader-spinner": "^4.0.0",
    "react-modal-video": "^1.2.8",
    "react-redux": "^7.2.4",
    "react-responsive-carousel": "^3.2.21",
    "react-router-dom": "^5.2.0",
    "react-scripts": "^4.0.3",
    "react-table": "^7.7.0",
    "reactstrap": "^8.9.0",
    "redux": "^4.1.0",
    "redux-thunk": "^2.3.0",
    "sweetalert2": "^11.0.18",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "ie 11",
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
Nitesh Jha
  • 99
  • 1
  • 1
  • 2

4 Answers4

5

Check to see if you have a local server running in another terminal (eg. localhost:3000 ).

If you do, end that server instance by terminating the batch job (with Ctrl+C) and try running npm run build again.

Daryn Brown
  • 71
  • 1
  • 6
1

I recently had this issue. Check your package.json for react-scripts, if the version is <5.0.0 upgrade it to at least "react-scripts": "5.0.0".

Do a yarn install or npm install again, then yarn build or npm run build as the case may be.

Let me know if this works for you! Cheers!

Yusuf Ganiyu
  • 842
  • 9
  • 8
0

If the process is stuck, it could be due to a lack in computing resources.

I would recommend investigating the currently running processes.

Try running sudo htop on a different terminal window and then run sudo npm run build.

You might find another process is taking too much memory, causing the build process to hang.

You may need to kill or restart such processes to complete the build. It would be a good idea to check why those processes take so much memory, but that's besides the topic.

Bar Kazzaz
  • 21
  • 2
0

I've also encountered this issue. I searched for many solutions and finally discovered that it was due to the insufficient memory on my server. The server got stuck while packaging because of the low memory. Please check if your server's memory usage is normal. If you're facing a similar problem, I recommend stopping other services first and then proceeding with the packaging