【问题标题】:Errors when running npm run build运行 npm run build 时出错
【发布时间】:2022-06-16 17:06:22
【问题描述】:

我正在尝试为 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

【问题讨论】:

  • 在你的 package.json 文件中,是否定义了构建命令?
  • 可能不会。 To see a list of scripts, run: npm run.
  • "build": "react-scripts build" 出现在我的“脚本”中,如果这是你的要求,但它仍然给我同样的错误行:(,天哪,我讨厌节点

标签: node.js reactjs npm terminal build


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 如果你的答案是检查“build”:“react-scripts build”是否存在于我的脚本中,不幸的是它确实存在,但它仍然让我的生活成为一个活生生的地狱,而不是让该死的构建文件夹:) 。对不起,我的语气,这让我整天感到沮丧
    • 也尝试创建一个npm i react-scripts --save-dev。为了确保它已安装。如果将 webpack.config.js 中的 output.path 设置为绝对路径 module.exports = { entry: ['./app/index.js'], output: { path: __dirname + '/build', filename: 'bundle.js' } },也可以选择尝试
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2021-03-03
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      • 1970-01-01
      • 2023-02-02
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多