简体   繁体   English

npm 错误! 缺少脚本:“构建”

[英]npm ERR! Missing script: "build"

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.我正在尝试部署一个 react 项目,但没有使用 create-react-app 来启动该项目,我使用了一个名为 createapp.dev 的站点,所以我不知道这是否是问题所在。 i included my package.json and an image of the error is as follows我包含了我的 package.json 并且错误的图像如下“错误”

    "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"
  }
}

You don't have a script called "build" in your package.json.您的 package.json 中没有名为“build”的脚本。 Try with "build-prod" instead!尝试使用“build-prod”!

npm run build means to run the script called build from that list you provided. npm run build表示从您提供的列表中运行名为build的脚本。 Your list doesn't have a script called build , so it fails.您的列表没有名为build的脚本,因此它失败了。

Your script is not having build command specified that's the reason npm run build will fail.您的脚本没有指定build命令,这就是npm run build失败的原因。

Following are the observation from your package.json scripts:以下是您的package.json脚本中的观察结果:

"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 .通常create-react-app使用Webpack作为它的模块捆绑器,这里它使用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.正如您在package.json中定义的那样,而不是npm run build try npm run build-prod这将使用src/index.html的 parcel 作为 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.通常npm run build将运行以下react-scripts build您可以尝试将以下内容添加到scripts中,但我怀疑它是否会起作用,因为需要根据使用的模块捆绑器创建构建。 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.如果它使用正确的模块捆绑器规则进行正确构建,那么它将运行,否则它将继续抛出错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM