Repository navigation
Description
Bug Description
module:react-native-dotenv Babel plugin breaks workletization in react-native-reanimated 4.x / react-native-worklets 0.8.x, causing a runtime crash:
[Worklets] Tried to synchronously call a non-worklet function 'addListener' on the UI thread.
The crash occurs because the dotenv Babel plugin transforms the AST in ways that prevent the Worklets Babel plugin from correctly identifying and marking workletizable functions. This is the same class of Babel transform conflict documented with React Compiler in software-mansion/react-native-reanimated#6826.
Environment
- React Native: 0.83.4
- Expo: 55.x (bare workflow)
- react-native-reanimated: 4.3.0-rc.0
- react-native-worklets: 0.8.0-rc.0
- react-native-dotenv: latest
- Platform: Android (also affects iOS)
Steps to Reproduce
- Create an Expo bare workflow project with RN 0.83.4, Reanimated 4.x, and Worklets 0.8.x
- Add
module:react-native-dotenvtobabel.config.jsplugins - Run the app with any Reanimated animation
- Crash:
[Worklets] Tried to synchronously call a non-worklet function 'addListener' on the UI thread
Isolation & Proof
We built an isolated demo app with the exact same RN/Reanimated/Worklets versions:
- Without
module:react-native-dotenvin Babel config → ✅ Works perfectly, no crash - With
module:react-native-dotenvin Babel config → ❌ Crash immediately
We also tried reordering the plugin (placing dotenv before/after react-native-worklets/plugin) — neither ordering resolves the crash. The Worklets plugin must be listed last per official docs, but dotenv's AST transforms interfere regardless of position.
Root Cause Analysis
The Worklets Babel plugin needs to identify functions that should run on the UI thread and mark them as "worklets." The dotenv plugin's aggressive environment variable inlining transforms the AST before or after workletization, breaking the worklet detection/annotation pipeline.
This is consistent with:
- React Compiler conflict (reanimated#6826) — same crash pattern, same root cause (Babel transform interference). Reanimated maintainer stated: "it's actually impossible to fix it on our end"
- expo-router conflict (expo#28933) — dotenv's aggressive inlining breaks expo-router's Babel transforms
- NativeWind conflict (SO thread) — Babel plugin order conflicts
Workaround / Fix
We migrated from react-native-dotenv to react-native-config:
- Remove
['module:react-native-dotenv', ...]frombabel.config.js - Install
react-native-config - Replace all
import { VAR } from '@env'with:import Config from 'react-native-config'; // Config.VAR
- Rebuild native apps
react-native-config reads .env at native build time (not via Babel transform), so it does not interfere with the Worklets Babel plugin pipeline.
Related Issues
- software-mansion/react-native-reanimated#6826 — React Compiler breaks workletization (same crash pattern)
- expo/expo#28933 — react-native-dotenv incompatible with expo-router
- dohooo/react-native-reanimated-carousel#900 — Same addListener crash in Expo 55 ecosystem
- Reanimated troubleshooting docs — Documents that mismatched Babel transforms cause "undefined behavior and errors"
Activity
github-actions commentedon Mar 18, 2026
Hey, thank you for opening this issue! 🙂 To boost priority on this issue and support open source please tip the team at https://issuehunt.io/r/goatandsheep/react-native-dotenv/issues/565
crbcchris commentedon Apr 15, 2026
is this likely to get fixed? - I can no longer get my app to work correctly using Expo 55
crbcchris commentedon Apr 17, 2026
@ericjoye Is this a fix that is easily patchable? Looking for a quick fix :-)
crbcchris commentedon Apr 27, 2026
@ericjoye Did you get time to look at this, or is it ongoing? Thanks in advance....
AndrianarivoAlpha commentedon May 5, 2026
Any update please?
AndersonRR commentedon May 18, 2026
I was facing the same issue. I just dropped the dotenv lib and refactored to use environment variables.
tjzel commentedon Jun 19, 2026
fixed in software-mansion/react-native-reanimated#9703
goatandsheep commentedon Jul 21, 2026
I'm looking at this now
goatandsheep commentedon Jul 23, 2026
@tjzel is this still needed?
tjzel commentedon Jul 23, 2026
Not really, it's fixed on our end