question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Reactions:37
  • Comments:77 (3 by maintainers)

github_iconTop GitHub Comments

57reactions
AlexKLWScommented, Apr 23, 2019

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"]

34reactions
amunimcommented, Apr 17, 2019

Have someone found a fix yet? I am stuck on this

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found