首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >npm运行<script-name>失败

npm运行<script-name>失败
EN

Stack Overflow用户
提问于 2022-10-13 10:04:39
回答 1查看 19关注 0票数 -1

我想按照开发、分期和生产这样的环境来构建React项目。

下面是package.json文件中脚本部分的快照。

代码语言:javascript
复制
"scripts": {
    "start development": "REACT_APP_ENV=development react-scripts start",
    "start staging": "REACT_APP_ENV=staging react-scripts start",
    "start production": "REACT_APP_ENV=production react-scripts start",
    "build development": "REACT_APP_ENV=development react-scripts build",
    "build staging": "REACT_APP_ENV=staging react-scripts build",
    "build production": "REACT_APP_ENV=production react-scripts build",
    "build": "react-scripts build",
    "start": "react-scripts start",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  } 

因此,根据脚本,“构建开发”应该为开发环境构建项目。现在,当我通过指定环境在项目主目录中运行以下命令时,(为暂存env进行暂存构建)

代码语言:javascript
复制
npm run 'build staging'

下面显示错误并命令退出

代码语言:javascript
复制
> testapp@0.1.0 build staging
> REACT_APP_ENV=staging react-scripts build

sh: 1: /tmp/build: not found

有趣的是,该命令在其他系统上运行非常好,并创建构建文件夹,没有任何问题,但它在我当前的系统上抛出了错误。

我所有的系统都在运行Ubuntu20.04.4LTS

伙计们知道有什么问题吗?

EN

回答 1

Stack Overflow用户

发布于 2022-10-14 06:44:10

交叉env添加为依赖项,并更改脚本以使用_而不是空格,如下所示,解决了这个问题

代码语言:javascript
复制
"scripts": {
    "start_development": "cross-env REACT_APP_ENV=development react-scripts start",
    "start_staging": "cross-env REACT_APP_ENV=staging react-scripts start",
    "start_production": "cross-env REACT_APP_ENV=production react-scripts start",
    "build_development": "cross-env REACT_APP_ENV=development react-scripts build",
    "build_staging": "cross-env REACT_APP_ENV=staging react-scripts build",
    "build_production": "cross-env REACT_APP_ENV=production react-scripts build",
    "build": "react-scripts build",
    "start": "react-scripts start",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  }

现在,以下命令在所有平台上运行,没有任何问题。

代码语言:javascript
复制
npm run build_staging
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74053925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档