运行 npm run build 时出错

发布于 2025-01-09 17:00:34 字数 373 浏览 0 评论 0原文

我尝试为 React 项目创建构建文件夹,但是当我运行命令“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

Im trying to create my built folder for a react project, but I get this error when I run the command '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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦旅人picnic 2025-01-16 17:00:34

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

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

in your package.json file add build script, for example:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
又爬满兰若 2025-01-16 17:00:34

您可以检查标准的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"
    ]
  }
}

You can check standard react package.json(which is located in root folder of your project) file:

{
  "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"
    ]
  }
}
忆离笙 2025-01-16 17:00:34

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

If the build is defined in your package.json file, make sure that you are executing the 'npm run build' in the correct folder hierarchy( use 'cd' with no arguments or 'pwd').

打小就很酷 2025-01-16 17:00:34

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

npm run build

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

那么您必须始终在此特定文件夹中运行该命令

npm run build

I was facing the same issue while running the command

npm run build

What I found was that I was running the command in the wrong folder and hence the error was sited. When I moved to the folder of my main project, and ran the same command it worked perfectly.
I think you are making the same mistake.
For eg:
If you have created a folder new_project, and then have created the react app in the folder(new_project) say, npx create-react-app project_folder

Then you must always run the command

npm run build

in this particular folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文