Cannot find module 'warnOnce' from 'react-native-implementation.js'
See original GitHub issue🐛 Bug Report
When requiring react-native in node context (e.g. jest) module warnOnce cannot be found. ● Test suite failed to run
Cannot find module 'warnOnce' from 'react-native-implementation.js'
To Reproduce
TestFile.js
import { PixelRatio } from 'react-native'
export default class TestFile {
}
TestFile.test.js
import TestFile from './TestFile'
test('test', () => {
...
})
Expected Behavior
warnOnce should be found and loaded just like invariant.
Workaround
As a workaround I’m mocking react-native dependency with jest.doMock('react-native', () => reactNativeMock))
Environment
info
React Native Environment Info:
System:
OS: macOS 10.14.3
CPU: (8) x64 Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
Memory: 3.06 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.10.0 - ~/.nvm/versions/node/v8.10.0/bin/node
Yarn: 1.13.0 - ~/.nvm/versions/node/v8.10.0/bin/yarn
npm: 6.8.0 - ~/.nvm/versions/node/v8.10.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 23, 25, 26, 27, 28
Build Tools: 21.1.2, 23.0.1, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.3
System Images: android-19 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5199772
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.1 => 0.59.0
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
react-native-rename: 2.4.0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:37
- Comments:77 (3 by maintainers)
Top Results From Across the Web
React Native Jest Error: Cannot find module 'warnOnce' from ...
So I tested some files to test project, and find out "react-native.config.js" file was the reason. If there is someone suffered this issue, ......
Read more >Cannot find module 'warnOnce' from 'react-native ...
When requiring react-native in node context (e.g. jest) module warnOnce cannot be found.
Read more >[Solved]-Cannot Find Module 'react-native' - appsloveworld
Coding example for the question Cannot Find Module 'react-native'-React ... Jest Error: Cannot find module 'warnOnce' from 'react-native-implementation.js' ...
Read more >React Native Testing Library - npm
The React Native Testing Library (RNTL) is a lightweight solution for testing React Native components. It provides light utility functions ...
Read more >Ios – react-native Unable to resolve module 'warnOnce'
... Unable to resolve module `warnOnce` from `node_modules/react-native/Libraries/react-native/react-native-implementation.js`: warnOnce could not be found ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have resolved this issue, and for me the problem was with
.bablerc
. For some reason I had"presets": ["module:react-native", "react-native"]
instead of"presets": ["module:metro-react-native-babel-preset"]
Have someone found a fix yet? I am stuck on this