Jest fails with TurboModuleRegistry 'RNLocalize' could not be found
Your error
Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNLocalize' could not be found. Verify that a module by this name is registered in the native binary.1 more line it can showFix it fast
Most common cause, 1 of 3No mock exists, so Jest loads the real native module
Add a manual mock at the project root, beside node_modules.
mkdir -p __mocks__
cat > __mocks__/react-native-localize.ts <<'EOF'
export * from "react-native-localize/mock";
EOFShort answer
Jest runs your React Native code in Node, so the native RNLocalize module behind react-native-localize is never registered and TurboModuleRegistry.getEnforcing throws. Create __mocks__/react-native-localize.ts next to node_modules that re-exports react-native-localize/mock, or list its folder in roots. Applies to react-native-localize 3.7, Jest 30 and React Native 0.88.
Which cause do you have?
Check two things together: whether a mock file for the package exists, and which folders Jest searches. A missing file points to cause 1. A file that exists outside every listed root points to cause 2. If Jest passes and only the app on a phone shows the error, read cause 3.
ls __mocks__/
npx jest --showConfig | grep -A3 '"roots"'Then find the line you see in this list and open its fix:
- 1No mock exists, so Jest loads the real native module
There is no __mocks__/react-native-localize file, and the stack trace runs from your store or a screen file into the package - 2The mock file sits in a folder Jest does not search
showConfig prints roots such as "<rootDir>/src", while your __mocks__ folder sits at the project root (or the other way round) - 3The app on a device or simulator was not rebuilt after installing the package
Jest passes, but the red screen appears in the running app right after react-native-localize was added
What does the error look like?
Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNLocalize' could not be found. Verify that a module by this name is registered in the native binary.TurboModuleRegistry.getEnforcing(...): 'RNLocalize' could not be found
Cause 1 of 3
No mock exists, so Jest loads the real native module
You seeThere is no __mocks__/react-native-localize file, and the stack trace runs from your store or a screen file into the package
Check
The RNLocalize could not be found error in Jest means a test imported react-native-localize, directly or through a store, hook or i18n file, and nothing replaced it. The package README says a native module has to be mocked for tests and ships a default mock for that purpose.
grep -rn "react-native-localize" src/ --include=*.ts --include=*.tsx --include=*.jsFix
Add a manual mock at the project root, beside node_modules. Jest picks up a mock for a node_modules package automatically, so no jest.mock call is needed in each test. Use the /mock/jest entry instead if you want jest.fn spies you can assert on.
mkdir -p __mocks__
cat > __mocks__/react-native-localize.ts <<'EOF'
export * from "react-native-localize/mock";
EOFVerify
The test that imported the Redux store now runs past the import, and the Invariant Violation is gone from the output.
npx jest path/to/store.test.tsConfirmed by raw.githubusercontent.com
Cause 2 of 3
The mock file sits in a folder Jest does not search
You seeshowConfig prints roots such as "<rootDir>/src", while your __mocks__ folder sits at the project root (or the other way round)
Check
Jest only finds a manual mock for a node_modules package when the __mocks__ folder lives inside one of the configured roots. With roots set to a src folder, a root-level mock is ignored and the native lookup still runs and fails with the same message.
npx jest --showConfig | grep -A5 '"roots"'Fix
Either move __mocks__ into a folder that roots lists, or add the project root to roots. Keep the folder name lowercase: Jest treats __mocks__ as case-sensitive.
// jest.config.js
module.exports = {
preset: "react-native",
roots: ["<rootDir>", "<rootDir>/src"],
};Verify
Run the suite again. Tests that touch locale code pass, and showConfig lists the folder that holds __mocks__.
npx jestConfirmed by jestjs.io
Cause 3 of 3
The app on a device or simulator was not rebuilt after installing the package
You seeJest passes, but the red screen appears in the running app right after react-native-localize was added
Check
Outside Jest the same invariant fires when the compiled app does not contain the RNLocalize native code. The message comes from getEnforcing in React Native and literally asks you to verify that the module is registered in the native binary. Installing the npm package alone does not change the binary.
grep -i localize ios/Podfile.lockFix
Install the iOS pods, as the package README reminds you to, then build and launch the app again: open the .xcworkspace in Xcode and press Run for iOS, and use npm run android for Android. A Metro reload is not enough, because only a new native build adds the module.
cd ios && pod install && cd ..
npm run androidVerify
The app opens without the red screen and getLocales() returns a list with at least one locale.
grep -c RNLocalize ios/Podfile.lockConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Add a __mocks__ file in the same pull request that adds any native module to package.json, so CI catches a missing mock on the first run.
- Keep Redux store files free of direct native imports; wrap locale calls in one small module that tests can replace.
- When you change roots in jest.config.js, move or re-check the __mocks__ folder in the same commit.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.