EAS Update not working EXPO_ROUTER_APP_ROOT is not defined
Build/Submit details page URL
No response
Summary
I recently switch using default Expo environment variables for eas. So i defined all my env variables in my eas.json. Since i made that change, eas update is no longer working.
Running: eas update --branch preview --platform ios doesn't work anymore.
eas build and local development is working fine tho.
Managed or bare?
Managed
Environment
expo-env-info 1.0.5 environment info: System: OS: macOS 13.4 Shell: 5.9 - /bin/zsh Binaries: Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v16.16.0/bin/yarn npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm Managers: CocoaPods: 1.11.3 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4 IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9014738 Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild npmPackages: @expo/metro-config: ^0.10.6 => 0.10.7 expo: ^49.0.5 => 49.0.7 react: 18.2.0 => 18.2.0 react-dom: 18.2.0 => 18.2.0 react-native: 0.72.3 => 0.72.3 react-native-web: ~0.19.6 => 0.19.7 npmGlobalPackages: eas-cli: 3.16.0 expo-cli: 6.3.10 Expo Workflow: managed
✔ Check Expo config for common issues ✔ Check package.json for common issues ✔ Check dependencies for packages that should not be installed directly ✔ Check for common project setup issues ✔ Check npm/ yarn versions ✔ Check Expo config (app.json/ app.config.js) schema ✔ Check that packages match versions required by installed Expo SDK ✔ Check for legacy global CLI installed locally ✔ Check that native modules do not use incompatible support packages ✔ Check that native modules use compatible support package versions for installed Expo SDK
Didn't find any issues with the project!
Error output
After Running: eas update --branch preview --platform ios
[expo-cli] Using src/app as the root directory for Expo Router.
[expo-cli] Experimental path aliases feature is enabled. Learn more: https://docs.expo.dev/guides/typescript/#path-aliases
[expo-cli] Starting Metro Bundler
[expo-cli]
[expo-cli]
[expo-cli] SyntaxError: node_modules/expo-router/_ctx.ios.tsx: node_modules/expo-router/_ctx.ios.tsx:Invalid call at line 2: process.env.EXPO_ROUTER_APP_ROOT
[expo-cli] First argument of require.context should be a string denoting the directory to require.
[expo-cli] Error: node_modules/expo-router/_ctx.ios.tsx:Invalid call at line 2: process.env.EXPO_ROUTER_APP_ROOT
[expo-cli] First argument of require.context should be a string denoting the directory to require.
Reproducible demo or steps to reproduce from a blank project
- Setup base project
- init eas and set environment variables for each profile
- run an eas update
I found the problem:
in front of my eas command, i had this:
NODE_ENV=test eas update --branch preview --platform ios
which was not required anymore because i was using the env in the eas.json and not my .env.test
And i saw in the expo router code that the EXPO_ROUTER_APP_ROOT is ignore in test.
// Skip loading the app root in tests.
// This is handled by the testing-library utils
process.env.NODE_ENV !== "test" &&
t.isIdentifier(parent.node.property, {
name: "EXPO_ROUTER_APP_ROOT",
}) &&
!parent.parentPath.isAssignmentExpression()
) {
I remove the NODE_ENV=test and everything is good.
How can we handle a staging .env file ? i tried using .env.staging but expo throw that this file is not supported..
How can we handle a staging .env file ? i tried using .env.staging but expo throw that this file is not supported..
NODE_ENV=staging at the build time, it will load env from .env.staging , I am also going to implement this in this week.
How can we handle a staging .env file ? i tried using .env.staging but expo throw that this file is not supported..
NODE_ENV=staging at the build time, it will load env from .env.staging , I am also going to implement this in this week.
@agrittiwari it doesnt work if you use eas cli because .env.staging is not a supported file. Im getting an error message saying this.
You can only use
.env.production .env.test .env.development
and same with additionnal .local extension
Expo CLI loads .env files as per the standard defined by the file resolution here based on their priority reference. It's also covered in the docs here.
As per that standard, .env.staging is not supported.
Hey @oliviercperrier have you find a way to work around this? I was also using NODE_ENV=test as staging to load variables and build failed with the expo-router error.
I found the problem:
in front of my eas command, i had this:
NODE_ENV=test eas update --branch preview --platform ioswhich was not required anymore because i was using the env in the eas.json and not my .env.test
And i saw in the expo router code that the EXPO_ROUTER_APP_ROOT is ignore in
test.// Skip loading the app root in tests. // This is handled by the testing-library utils process.env.NODE_ENV !== "test" && t.isIdentifier(parent.node.property, { name: "EXPO_ROUTER_APP_ROOT", }) && !parent.parentPath.isAssignmentExpression() ) {I remove the NODE_ENV=test and everything is good.
I'm also facing a similar issue, but I'm not using EAS. I need to load my test environment variables when running start, run and so on... Example NODE_ENV=test expo run:ios. But I'm just presented with this error:
error: node_modules/expo-router/_ctx.ios.js: node_modules/expo-router/_ctx.ios.js:Invalid call at line 2: process.env.EXPO_ROUTER_APP_ROOT
First argument of `require.context` should be a string denoting the directory to require.
standard .env is not enough. NODE_ENV=test behaviour seems different so it's not suitable to replace staging env. Hope expo can support more in EXPO_PUBLIC.
I found the problem:
in front of my eas command, i had this:
NODE_ENV=test eas update --branch preview --platform ioswhich was not required anymore because i was using the env in the eas.json and not my .env.test
And i saw in the expo router code that the EXPO_ROUTER_APP_ROOT is ignore in
test.// Skip loading the app root in tests. // This is handled by the testing-library utils process.env.NODE_ENV !== "test" && t.isIdentifier(parent.node.property, { name: "EXPO_ROUTER_APP_ROOT", }) && !parent.parentPath.isAssignmentExpression() ) {I remove the NODE_ENV=test and everything is good.
You da real MVP!
Permalink to the code in OP's comment describing the root cause: https://github.com/expo/expo/blob/a52d0a5e71c01673ee920c83565e759ca2165d5c/packages/babel-preset-expo/src/expo-router-plugin.ts#L56C13-L68C14