taro icon indicating copy to clipboard operation
taro copied to clipboard

执行命令有两个mode 不一致就会报process is not defined

Open RStar-F opened this issue 2 years ago • 2 comments

相关平台

微信小程序

小程序基础库: 2.14.1 使用框架: React

复现步骤

官方ts react模板,增加两个环境变量文件,.env.dev和.env.prod, package.json 里面在两个命令后面分别加上--mode dev 和 --mode prod ,在环境变量文件里面定义环境变量TARO_APP_API,在项目中使用process.env.TARO_APP_API, 页面会报错process is not defined

期望结果

能取到环境变量的值

实际结果

页面会报错process is not defined

环境信息

 Taro CLI 3.6.18 environment info:
    System:
      OS: macOS 12.5.1
      Shell: 5.8.1 - /bin/zsh
    Binaries:
      Node: 14.21.3 - ~/Library/Caches/fnm_multishells/39047_1700215509256/bin/node
      Yarn: 1.22.19 - /usr/local/bin/yarn
      npm: 6.14.18 - ~/Library/Caches/fnm_multishells/39047_1700215509256/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.18 => 3.6.18
      @tarojs/components: 3.6.18 => 3.6.18
      @tarojs/helper: 3.6.18 => 3.6.18
      @tarojs/plugin-framework-react: 3.6.18 => 3.6.18
      @tarojs/plugin-platform-alipay: 3.6.18 => 3.6.18
      @tarojs/plugin-platform-h5: 3.6.18 => 3.6.18
      @tarojs/plugin-platform-jd: 3.6.18 => 3.6.18
      @tarojs/plugin-platform-qq: 3.6.18 => 3.6.18
      @tarojs/plugin-platform-swan: 3.6.18 => 3.6.18
      @tarojs/plugin-platform-tt: 3.6.18 => 3.6.18
      @tarojs/plugin-platform-weapp: 3.6.18 => 3.6.18
      @tarojs/react: 3.6.18 => 3.6.18
      @tarojs/runtime: 3.6.18 => 3.6.18
      @tarojs/shared: 3.6.18 => 3.6.18
      @tarojs/taro: 3.6.18 => 3.6.18
      @tarojs/taro-loader: 3.6.18 => 3.6.18
      @tarojs/webpack5-runner: 3.6.18 => 3.6.18
      babel-preset-taro: 3.6.18 => 3.6.18
      eslint-config-taro: 3.6.18 => 3.6.18
      react: ^18.0.0 => 18.2.0

补充信息

如果执行命令中只写一个--mode dev 或者--mode prod ,执行结果正常,只有两个同时存在的时候会报错

RStar-F avatar Nov 21 '23 03:11 RStar-F

我也碰到这个问题,只保留一个mode就可以

zblzbl1991 avatar Dec 20 '23 05:12 zblzbl1991

2024年这个问题还存在吗?需要多个环境的环境配置。例如

"build:weapp-test:upload": "taro build --type weapp --mode test --upload",
"build:weapp:upload": "taro build --type weapp --mode prod --upload",
"dev:weapp": "npm run build:weapp -- --mode dev --watch"

cat-kun avatar Feb 01 '24 07:02 cat-kun