NodeJS 运行npm run build时出错

vaj7vani  于 2023-03-29  发布在  Node.js
关注(0)|答案(4)|浏览(357)

我试图为react项目创建我的built文件夹,但是当我运行命令'npm run build'时,我得到了这个错误

(base) tazar@Tazs-Air nft-minter-tutorial-main % npm run build
npm ERR! Missing script: "build"
npm ERR! 
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/tazar/.npm/_logs/2022-02-25T01_15_14_544Z-debug.log
jw5wzhpr

jw5wzhpr1#

在package.json文件中添加构建脚本,例如:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
oug3syen

oug3syen2#

你可以查看react package.json文件(位于你项目的根目录下):

{
  "name": "print",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
  },
  "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": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
6tr1vspr

6tr1vspr3#

如果构建是在package.json文件中定义的,请确保在正确的文件夹层次结构中执行'npm run build'(使用不带参数的'cd'或'pwd')。

kzipqqlq

kzipqqlq4#

我在运行命令时也遇到了同样的问题

npm run build

我发现我在错误的文件夹中运行命令,因此错误被定位。当我移动到我的主项目的文件夹,并运行相同的命令时,它工作得很好。我认为你犯了同样的错误。例如:如果您已经创建了一个文件夹new_project,然后在文件夹(new_project)中创建了react应用程序,比如说,npx create-react-app project_folder
则必须始终运行命令

npm run build

在这个文件夹里

相关问题