我想按照开发、分期和生产这样的环境来构建React项目。
下面是package.json文件中脚本部分的快照。
"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进行暂存构建)
npm run 'build staging'下面显示错误并命令退出
> testapp@0.1.0 build staging
> REACT_APP_ENV=staging react-scripts build
sh: 1: /tmp/build: not found有趣的是,该命令在其他系统上运行非常好,并创建构建文件夹,没有任何问题,但它在我当前的系统上抛出了错误。
我所有的系统都在运行Ubuntu20.04.4LTS
伙计们知道有什么问题吗?
发布于 2022-10-14 06:44:10
将交叉env添加为依赖项,并更改脚本以使用_而不是空格,如下所示,解决了这个问题
"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"
}现在,以下命令在所有平台上运行,没有任何问题。
npm run build_staginghttps://stackoverflow.com/questions/74053925
复制相似问题