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

环境变量TARO_APP_ID无效 #14979

Closed
Linxiaoxxx opened this issue Dec 13, 2023 · 6 comments · Fixed by #15328, #15361, #15427 or #15496
Closed

环境变量TARO_APP_ID无效 #14979

Linxiaoxxx opened this issue Dec 13, 2023 · 6 comments · Fixed by #15328, #15361, #15427 or #15496
Assignees
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@Linxiaoxxx
Copy link

相关平台

微信小程序

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

复现步骤

在.env.development 和 .env.production 文件分别配置 TARO_APP_ID="wxc...."
使用npm run build:weapp 无效从开发环境的appid切换为生产环境的

期望结果

可以根据环境正常切换

实际结果

无法根据环境切换

环境信息

Taro CLI 3.6.16 environment info:
    System:
      OS: Windows 10 10.0.19045    
    Binaries:
      Node: 18.0.0 - ~\AppData\Local\Temp\yarn--1702441244198-0.6516858049189154\node.CMD
      Yarn: 1.22.19 - ~\AppData\Local\Temp\yarn--1702441244198-0.6516858049189154\yarn.CMD
      npm: 8.6.0 - D:\nodejs\npm.CMD
    npmPackages:
      @tarojs/cli: 3.6.16 => 3.6.16
      @tarojs/components: 3.6.16 => 3.6.16
      @tarojs/helper: 3.6.16 => 3.6.16
      @tarojs/plugin-framework-react: 3.6.16 => 3.6.16
      @tarojs/plugin-html: ^3.6.16 => 3.6.16
      @tarojs/plugin-platform-alipay: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-h5: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-jd: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-qq: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-swan: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-tt: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-weapp: 3.6.16 => 3.6.16
      @tarojs/react: 3.6.16 => 3.6.16
      @tarojs/runtime: 3.6.16 => 3.6.16
      @tarojs/shared: 3.6.16 => 3.6.16
      @tarojs/taro: 3.6.16 => 3.6.16
      @tarojs/taro-loader: 3.6.16 => 3.6.16
      @tarojs/webpack5-runner: 3.6.16 => 3.6.16
      babel-preset-taro: 3.6.16 => 3.6.16
      eslint-config-taro: 3.6.16 => 3.6.16
      react: ^18.0.0 => 18.2.0
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Dec 13, 2023
@bigmeow
Copy link
Member

bigmeow commented Dec 20, 2023

详细提供一下 package.jsonscripts 看看

@CanonLs
Copy link

CanonLs commented Dec 21, 2023

@bigmeow 帮忙看一下我的问题,以下是我的配置
"scripts": {
"build:weapp": "taro build --type weapp",
"build:swan": "taro build --type swan",
"build:alipay": "taro build --type alipay",
"build:tt": "taro build --type tt",
"build:h5": "taro build --type h5",
"build:rn": "taro build --type rn",
"build:qq": "taro build --type qq",
"build:jd": "taro build --type jd",
"build:quickapp": "taro build --type quickapp",
"dev:weapp": "taro build --type weapp --watch --env production",
"dev:swan": "npm run build:swan -- --watch",
"dev:alipay": "npm run build:alipay -- --watch",
"dev:tt": "npm run build:tt -- --watch",
"dev:h5": "npm run build:h5 -- --watch",
"dev:rn": "npm run build:rn -- --watch",
"dev:qq": "npm run build:qq -- --watch",
"dev:jd": "npm run build:jd -- --watch",
"dev:quickapp": "npm run build:quickapp -- --watch",
"test": "jest"
},

@CanonLs
Copy link

CanonLs commented Dec 21, 2023

@bigmeow 并且还有热重载无效,不能实时更新小程序开发工具控制台输出了Page loaded但是页面内容并没有更新

@Madou-Shinni
Copy link

相关平台

微信小程序

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

复现步骤

在.env.development 和 .env.production 文件分别配置 TARO_APP_ID="wxc...." 使用npm run build:weapp 无效从开发环境的appid切换为生产环境的

期望结果

可以根据环境正常切换

实际结果

无法根据环境切换

环境信息

Taro CLI 3.6.16 environment info:
    System:
      OS: Windows 10 10.0.19045    
    Binaries:
      Node: 18.0.0 - ~\AppData\Local\Temp\yarn--1702441244198-0.6516858049189154\node.CMD
      Yarn: 1.22.19 - ~\AppData\Local\Temp\yarn--1702441244198-0.6516858049189154\yarn.CMD
      npm: 8.6.0 - D:\nodejs\npm.CMD
    npmPackages:
      @tarojs/cli: 3.6.16 => 3.6.16
      @tarojs/components: 3.6.16 => 3.6.16
      @tarojs/helper: 3.6.16 => 3.6.16
      @tarojs/plugin-framework-react: 3.6.16 => 3.6.16
      @tarojs/plugin-html: ^3.6.16 => 3.6.16
      @tarojs/plugin-platform-alipay: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-h5: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-jd: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-qq: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-swan: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-tt: 3.6.16 => 3.6.16
      @tarojs/plugin-platform-weapp: 3.6.16 => 3.6.16
      @tarojs/react: 3.6.16 => 3.6.16
      @tarojs/runtime: 3.6.16 => 3.6.16
      @tarojs/shared: 3.6.16 => 3.6.16
      @tarojs/taro: 3.6.16 => 3.6.16
      @tarojs/taro-loader: 3.6.16 => 3.6.16
      @tarojs/webpack5-runner: 3.6.16 => 3.6.16
      babel-preset-taro: 3.6.16 => 3.6.16
      eslint-config-taro: 3.6.16 => 3.6.16
      react: ^18.0.0 => 18.2.0

我和你遇到了一样的问题,很遗憾taro init xxx 拉取的脚手架之中无法让你在开发环境获取环境变量

这里需要手动修改启动命令

这是我的目录,你可以看到我的三个env文件

image

我在微信小程序开发环境中手动修改了启动命令
添加了 --mode dev

image

最后我成功实现了获取

image

@videni
Copy link

videni commented Apr 1, 2024

同样的问题,到底怎么解决的呢? @Linxiaoxxx @bigmeow

anyesu added a commit to anyesu/taro-demo that referenced this issue Apr 1, 2024
@anyesu
Copy link
Contributor

anyesu commented Apr 1, 2024

同样的问题,到底怎么解决的呢? @Linxiaoxxx @bigmeow

环境变量配置文件的文件名按下面这样改:

.env.dev -> .env.development
.env.prod -> .env.production

命令中 --mode xxx 读取的配置文件就是 .env.xxx 文件:

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
Archived in project
6 participants