typescriptreact-nativeexpo

"Invalid module name in augmentation, module '@env' cannot be found." - not using import


Recently I upgraded from expo version 51 to 53. I noticed the following typescript error Invalid module name in augmentation, module '@env' cannot be found....

Problem

Many .tsx and .ts files depend on this. Some of our config files also depend on this...

Babel/Env Dependancies

package.json dependancy

Packages Updated

"dependencies":
  "@expo/vector-icons": "^14.0.2" -> "^14.1.0"
  "@react-native-async-storage/async-storage": "1.23.1" -> "^1.24.0"
  "@react-native-community/netinfo": "11.3.1" -> "^11.4.1"
  "@react-native-firebase/app": "^21.7.1" -> "^22.1.0"
  "@react-native-firebase/auth": "^21.7.1" -> "^22.1.0"
  "@react-native-firebase/crashlytics": "^21.7.1" -> "^22.1.0"
  "@react-navigation/native": "^6.1.18" -> "^7.1.8"
  "@react-navigation/stack": "^6.4.1" -> "^7.3.1"
  "axios": "^1.7.7" -> "^1.9.0"
  "core-js": "^3.38.1" -> "^3.42.0"
  "expo": "~51.0.39" -> "~53.0.7"
  "expo-auth-session": "~5.5.2" -> "^6.1.5"
  "expo-build-properties": "~0.12.5" -> "^0.14.6"
  "expo-constants": "~16.0.2" -> "^17.1.5"
  "expo-file-system": "~17.0.1" -> "^18.1.9"
  "expo-image-manipulator": "~12.0.5" -> "^13.1.5"
  "expo-image-picker": "~15.1.0" -> "^16.1.4"
  "expo-location": "~17.0.1" -> "^18.1.4"
  "expo-secure-store": "~13.0.2" -> "^14.2.3"
  "expo-splash-screen": "~0.27.7" -> "^0.30.8"
  "expo-status-bar": "~1.12.1" -> "~2.2.3"
  "expo-system-ui": "~3.0.7" -> "^5.0.7"
  "expo-web-browser": "~13.0.3" -> "^14.1.6"
  "formik": "^2.4.6"
  "jwt-decode": "^4.0.0"
  "lodash": "^4.17.21"
  "react": "18.2.0" -> "19.0.0"
  "react-native": "0.74.5" -> "0.79.2"
  "react-native-device-info": "^11.1.0" -> "^14.0.4"
  "react-native-element-dropdown": "^2.12.1" -> "^2.12.4"
  "react-native-gesture-handler": "~2.16.1" -> "^2.25.0"
  "react-native-get-random-values": "~1.11.0" -> "^1.11.0"
  "react-native-safe-area-context": "4.10.5" -> "^5.4.0"
  "react-native-screens": "3.31.1" -> "^4.10.0"
  "react-native-shadow-2": "^7.1.0" -> "^7.1.1"
  "react-native-svg": "15.2.0" -> "^15.11.2"
  "react-native-switch": "^1.5.1"
  "react-native-toast-message": "^2.2.0" -> "^2.3.0"
  "react-query": "^3.39.3" -> "@tanstack/react-query": "^5.75.2"
  "scandit-react-native-datacapture-barcode": "^6.27.0" -> "^7.2.1"
  "scandit-react-native-datacapture-core": "^6.27.0" -> "^7.2.1"
  "uri-scheme": "^1.2.2" -> "^1.4.7"
  "uuid": "^10.0.0" -> "^11.1.0"
  "yup": "^1.4.0" -> "^1.6.1"
  "zustand": "^4.5.5" -> "^5.0.4"

"devDependencies": ->
  "@babel/core": "^7.20.0" -> "^7.25.2"
  "@types/lodash": "^4.17.7" -> "^4.17.16"
  "@types/node": "^22.10.1" -> "^22.15.5"
  "@types/react": "~18.2.45" -> "~19.0.10"
  "@types/uuid": "^10.0.0"
  "cross-env": "^7.0.3"
  "react-native-dotenv": "^3.4.11"
  "typescript": "~5.3.3" -> "~5.8.3"

Is there a quick and easy fix for this?


Solution

  • The project runs okay, it's only a typescript error.

    Changed the filename Env.ts -> Env.d.ts and the error went away... enter image description here

    enter image description here