Home > Enterprise >  npm ERR! Missing script: "build"
npm ERR! Missing script: "build"

Time:07-09

I am trying to deploy a react project but did not use create-react-app to start the project i used a site called createapp.dev so i don't know if that is the issue. i included my package.json and an image of the errorenter image description here

"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"clean": "rm dist/bundle.js",
"start": "react-scripts start",
"build-prod": "parcel build src/index.html"

}, "dependencies": { "node-sass": "^7.0.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.3.0" }, "devDependencies": { "@babel/core": "^7.18.5", "@babel/preset-env": "^7.18.2", "@babel/preset-react": "^7.17.12", "gh-pages": "^4.0.0", "parcel-bundler": "^1.12.5", "prettier": "^2.7.1" } }

CodePudding user response:

You don't have a script called "build" in your package.json. Try with "build-prod" instead!

CodePudding user response:

npm run build means to run the script called build from that list you provided. Your list doesn't have a script called build, so it fails.

CodePudding user response:

Your script is not having build command specified that's the reason npm run build will fail.

Following are the observation from your package.json scripts:

"scripts": {
    "predeploy": "npm run build", // will run the code before deploy
    "deploy": "gh-pages -d build", // gh-pages => github pages hence this is for github deployment
    "clean": "rm dist/bundle.js", // rm to remove the bundle.js
    "start": "react-scripts start", // to start the react-app
    "build-prod": "parcel build src/index.html" // to make build using parcel module bundler
  }

Typically create-react-app uses Webpack as it's module bundler and here it's using Parcel. Depending on bundler there are different functionality and syntax as well as approach for the code from start to end.

As defined in your package.json instead of npm run build try npm run build-prod this will create build with parcel for src/index.html as root.

Generally npm run build will run the following react-scripts build you can try adding following into the scripts but I doubt it will work as build need to be created based on the module bundler used. You can give it a shot by adding following into scripts.

"build": "react-scripts build",

If it makes proper build with proper module bundler rules then it will run or else it will keep throwing errors.

  • Related