expo / expo-webpack-integrations

Packages used to integrate Expo in Webpack-based projects.
8 stars 1 forks source link

Enviroment variables starts with EXPO_PUBLIC_ not working on web platform bundled by webpack #22

Open BaffinLee opened 10 months ago

BaffinLee commented 10 months ago

Summary

Accourding to expo docs https://docs.expo.dev/guides/environment-variables/

Enviroment variables starts with EXPO_PUBLIC_ in .env file should be accessable with process.env after expo SDK 49, but which is not when a project is bundled by webpack for web platform.

Environment

expo-env-info 1.0.5 environment info: System: OS: Windows 10 10.0.19045 Binaries: Node: 18.17.1 - D:\software\nodejs\node.EXE Yarn: 1.22.11 - ~\AppData\Roaming\npm\yarn.CMD npm: 9.6.7 - D:\software\nodejs\npm.CMD npmPackages: @expo/webpack-config: ^19.0.0 => 19.0.0 expo: ~49.0.15 => 49.0.16 react: 18.2.0 => 18.2.0 react-dom: 18.2.0 => 18.2.0 react-native: 0.72.6 => 0.72.6 react-native-web: ~0.19.6 => 0.19.9 Expo Workflow: managed

Please specify your device/emulator/simulator platform, model and version

web

Error output

No response

Reproducible demo or steps to reproduce from a blank project

npx create-expo-app my-app
npx expo install react-dom react-native-web @expo/webpack-config

create a file name .env, put EXPO_PUBLIC_API_PATH=/ in it

use this enviroment variable in App.js, like this console.log(process.env.EXPO_PUBLIC_API_PATH)

npm run web
lucassaid commented 9 months ago

I'm facing the same issue, do you have some workaround for this?

BaffinLee commented 9 months ago

I'm facing the same issue, do you have some workaround for this?

Metro works, but some behavior is different than Webpack https://docs.expo.dev/guides/customizing-metro/