Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
frxing opened this issue Nov 21, 2023 · 2 comments
Open

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

frxing opened this issue Nov 21, 2023 · 2 comments
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@frxing
Copy link

frxing commented Nov 21, 2023

相关平台

微信小程序

小程序基础库: 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 ,执行结果正常,只有两个同时存在的时候会报错

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Nov 21, 2023
@zblzbl1991
Copy link

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

@cat-kun
Copy link

cat-kun commented Feb 1, 2024

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
Status: Todo
Development

No branches or pull requests

3 participants