Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'warnOnce' from 'react-native-implementation.js' #23943

Closed
flodev opened this issue Mar 15, 2019 · 77 comments
Closed

Cannot find module 'warnOnce' from 'react-native-implementation.js' #23943

flodev opened this issue Mar 15, 2019 · 77 comments
Labels
Bug Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Resolution: Locked This issue was locked by the bot.

Comments

@flodev
Copy link

flodev commented Mar 15, 2019

πŸ› 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
@c4ss
Copy link

c4ss commented Mar 17, 2019

Getting the same error when trying to run yarn run metro build index.js --out ./dist/

with versions

    react 16.6.3
    react-native 0.58.6

Stemming from #22109 so maybe babel issue?

@varunchopraWB
Copy link

I have this same issue when running our react-native ios app.
with versions
"react": "^16.8.5", "react-native": "^0.59.2",

@GreenRidingHood
Copy link

GreenRidingHood commented Mar 29, 2019

"Cannot find module 'warnOnce' "error, is there any solution for that.

also i dont use pod *

React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
Binaries:
Node: 10.15.3 - /usr/local/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/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: 23.0.1, 24.0.2, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.1, 27.0.3, 28.0.1, 28.0.3
System Images: android-28 | Google APIs Intel x86 Atom_64
IDEs:
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.2 => 0.59.2
npmGlobalPackages:
react-native-cli: 2.0.1

my xcode error::

warning: the transform cache was reset.
Loading dependency graph, done.
error index.js: Cannot find module 'warnOnce'

  • [[ false != true ]]
  • [[ ! -f /Users/me/Library/Developer/Xcode/DerivedData/build/Build/Products/Release-
    iphonesimulator/myapp.app/main.jsbundle ]]
  • echo 'error: File /Users/me/Library/Developer/Xcode/DerivedData/build/Build/Products/Release-
    iphonesimulator/myapp.app/main.jsbundle does not exist. This must be a bug with'
    error: File /Users/me/Library/Developer/Xcode/DerivedData/build/Build/Products/Release-
    iphonesimulator/myapp.app/main.jsbundle does not exist. This must be a bug with

@GreenRidingHood
Copy link

@flodev were u able to solve that issue??? or pass ?? thx

@liron-navon
Copy link

liron-navon commented Mar 30, 2019

It is still an issue, have you found a solution?

@gzcheng
Copy link

gzcheng commented Apr 1, 2019

This is what I have tried:

  1. remove all references of warnOnce in react-native-implementation.js
  • run the iOS build again
  • got the following error:
    bundling failed: Error: Cannot find module 'warnOnce' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object.<anonymous> (/Users/gzcheng/Documents/ellentube-mobile/node_modules/react-native/Libraries/react-native/react-native-implementation.js:14:18) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12)
  1. copy the warnOnce.js from /node_modules⁩/react-native/⁨Libraries⁩/Utilities to /node_modules⁩/react-native⁩/⁨Libraries⁩/⁨react-native⁩.
  • got a duplicate modul name error.

That tells me that packager is able to find the warnOnce module. I am not an expert on this, but it sounds like some we maybe using some incompatible library versions?
This issue has been bothering for about a week... would like to have it resolved soon...

@GreenRidingHood
Copy link

GreenRidingHood commented Apr 1, 2019

@rickhanlonii , i tried your suggestion from other issue page, i still see the error, i know limited people and so many new xcode ticket :( , good luck for all tickets

@flodev
Copy link
Author

flodev commented Apr 2, 2019

Hi @GreenRidingHood,
I haven't had the issue while building and deploying to devices. It was only an issue when I tried to include the react-native dependency in a jest test.
In my first post I described how I bypassed the issue with mocking the react-native dependency.
My guess is that you have included a script somewhere in you build process that tries to access react-native dependency. Have you tried setting up a new project and deploying? Maybe you can compare your project setup with the new project setup and figure it out.

@GreenRidingHood
Copy link

@flodev i will try your suggestions, :) about script , anything can happen. While i was trying to run new xcode 10 , so many errors, issues or fixes i go over, i even dont remember :) thx

@amunim
Copy link

amunim commented Apr 17, 2019

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

@sonukj
Copy link

sonukj commented Apr 17, 2019

I'm facing this issue for the past 2 days. Tried many solutions but no result yet
I don't think so downgrading the versions of libraries will be a permanent solution for this, should find some valid solutions.

@amunim
Copy link

amunim commented Apr 17, 2019

What is the appropriate version to downgrade to, then?

@sonukj
Copy link

sonukj commented Apr 17, 2019

I created a new react-native project with a newer version (0.59.4). still facing the same issue
I downgraded the react-native version to 0.58.0 and created the web-pack configuration.all worked fine. I think the actual issue is with the warnOnce.js file. @amunim can u try with the older version(0.58.0)

matei-radu added a commit to matei-radu/react-native-in-app-browser that referenced this issue Apr 19, 2019
@GreenRidingHood
Copy link

@sonukj yeah.. i downgraded to 0.58.0 , i dont have that error anymore, but glog , i wonder when i will be able to use xcode10 and react-native without any problem :(

@sonukj
Copy link

sonukj commented Apr 22, 2019

@sonukj yeah.. i downgraded to 0.58.0 , i dont have that error anymore, but glog , i wonder when i will be able to use xcode10 and react-native without any problem :(

did you try updating your pod???

@knspatel
Copy link

facing same issue .
I have used below version.

  "react": "16.8.3",
   "react-native": "^0.59.4",

any workaround?

@AlexKLWS
Copy link

Having the same issue with "react-native": "^0.59.4"

@amunim
Copy link

amunim commented Apr 23, 2019

Update:
I finally gave up on react native and from this docs facebook I used expo cli to generate my app Which does not use flow so even if my IDE(VS Code) has flow enabled the project doesn't support it hence it works flawlessly.

For those Who want to use native features such as AndroidManifest, opening up the project with android studio and/or XCode simply run npm run efect or yarn eject for yarn

This is the only solution(s) I've found and I don't mind using it.

@AlexKLWS
Copy link

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

@sonukj
Copy link

sonukj commented Apr 23, 2019

But from Babel 7 onwards they are not using .babelrc config instead having separate babel.config.js file. Can you tell me reason how the problem solved by changing the configuration?

@amunim
Copy link

amunim commented Apr 23, 2019

@sonukj to make this work in babel.config.json just paste the correct line which alex has mentioned AS IT IS and apply the comma's to fix the json if a compile error occurs
If it already consists a presets object then append ["module:metro-react-native-babel-preset"] to the value of it

@AlexKLWS
Copy link

AlexKLWS commented Apr 23, 2019

@sonukj I might be wrong, but as I understand from here and here, .babelrc is applied to the single package only, when babel.config.json is a general project-wide configuration. In my case, I am using .babelrc because of babel-plugin-module-resolver

@GreenRidingHood
Copy link

@sonukj @amunim solution did not work for me,
i have babel.config.json file and like this,

module.exports = {
presets: ['module:metro-react-native-babel-preset'],
};

but still having that error in my xcode

  • node /Users/me/dev/myapp/node_modules/react-native/cli.js bundle --entry-file index.js --platform ios --dev false --reset-cache --bundle-output /Users/me/dev/myapp/ios/build/Build/Products/Release-iphonesimulator/myapp.app/main.jsbundle --assets-dest /Users/me/dev/myapp/ios/build/Build/Products/Release-iphonesimulator/myapp.app
    warning: the transform cache was reset.
    Loading dependency graph, done.
    error index.js: Cannot find module 'warnOnce'. Run CLI with --verbose flag for more details.
  • [[ false != true ]]
  • [[ ! -f /Users/me/dev/myapp/ios/build/Build/Products/Release-iphonesimulator/myapp.app/main.jsbundle ]]
  • echo 'error: File /Users/me/dev/myapp/ios/build/Build/Products/Release-iphonesimulator/myapp.app/main.jsbundle does not exist. This must be a bug with'
    error: File /Users/me/dev/myapp/ios/build/Build/Products/Release-iphonesimulator/myapp.app/main.jsbundle does not exist. This must be a bug with

react-native version 0.59.5 still have same issue,
if i downgraded to 58, yes i dont get this error anymore, but i am getting this kind of error

::ffff:127.0.0.1 - - [24/Apr/2019:19:43:46 +0000] "GET /index.ios.bundle?platform=ios&dev=true&minify=false HTTP/1.1" 200 - "-" "myapp/6 CFNetwork/975.0.3 Darwin/17.7.0"
Error: Unable to resolve module ./index.ios from /Users/me/dev/myapp/.: The module ./index.ios could not be found from /Users/me/dev/myapp/.. Indeed, none of these files exist:

  • /Users/me/dev/myapp/index.ios(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
  • /Users/me/dev/myapp/index.ios/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
    at ModuleResolver.resolveDependency (/Users/me/dev/myapp/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (/Users/me/dev/myapp/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (/Users/me/dev/myapp/node_modules/metro/src/node-haste/DependencyGraph.js:273:16)
    at /Users/me/dev/myapp/node_modules/metro/src/lib/transformHelpers.js:261:42
    at Server. (/Users/me/dev/myapp/node_modules/metro/src/Server.js:935:41)
    at Generator.next ()
    at asyncGeneratorStep (/Users/me/dev/myapp/node_modules/metro/src/Server.js:73:24)
    at _next (/Users/me/dev/myapp/node_modules/metro/src/Server.js:93:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)

anyway after that RN58 error, i am using 59 again but ..
... agghh i have to use xcode 10 with react-native :(

xcode Version 10.1 (10B61)
react-native-cli: 2.0.1
react-native: 0.59.5

@undsoft
Copy link

undsoft commented May 1, 2019

Okay, this is somewhat magical, but for me the problem was fixed when I deleted my jest.config.js and moved config to package.json, even despite the contents being identical.

@deysayantan
Copy link

deysayantan commented May 2, 2019

Okay, this is somewhat magical, but for me the problem was fixed when I deleted my jest.config.js and moved config to package.json, even despite the contents being identical.

Didn't work for me... I don't know why

@IAmMarcellus
Copy link

@empyrical my babel.config.js:

module.exports = { presets: ['module:metro-react-native-babel-preset'], };

And I'm not using a .babelrc

@IAmMarcellus
Copy link

@empyrical If I open node_modules/react-native/Libraries/Utilities/warnOnce.js, my IDE show an error in places saying that "types can only be used in a .ts file". Could that have anything to do with the problem?

@hcantave
Copy link

I realize by adding module.exports = { presets: ['module:metro-react-native-babel-preset'], }; I can run some command like "babel src/ -d lib/ " without "warnOnce" error. But I have the error if I try to run this command "yarn run metro build index.js -O index.android.bundle" or "yarn android"

@josecarlosns
Copy link

I'm having this same issue when trying to run tests, but instead of jest I'm using mocha (planning on migrating to jest in the future).

@IAmMarcellus
Copy link

@empyrical Any suggestions? I had to update to 0.60.X to implement the facebook SDK, but I can't do anything now that I've updated because of this issue. I've followed all of the suggestions, but nothing is working and I really need to release the update for my app, but can't until this is resolved so any help would be MUCH appreciated.

@ghost
Copy link

ghost commented Sep 16, 2019

I was fixed this error. I add module.exports = { preset: 'react-native', ....} in file jest.config.js.
I used "react": "16.8.6", "react-native": "0.60.5",
Device macOS Mojave version 10.14.5

@daniil-orlov
Copy link

I have no idea why, but for me this problem was solved when I removed this roots config:
roots: [ '<rootDir>/src' ],
from jest.config.js
Out of the box by react-native-cli I had preset: 'react-native'.

@alexander-mozolevsky
Copy link

If you have jest.config.js file inside your root directory,
you should add preset: 'react-native', property to module.export

so It will look like:

jest.config.js

module.exports = {
	preset: 'react-native',
        ...
};

@tomtargosz
Copy link
Contributor

I'm having the same issue, Cannot find module 'Dimensions'. No mocks for react-native are working. On 0.60.6 everything works fine but both 0.61.0 and 0.61.1 are giving this error.

@wouterds
Copy link

Why is this issue closed? Still facing the same issue, on different computers.

@ghasemikasra39
Copy link

info 
  React Native Environment Info:
    System:
      OS: Linux 4.15 Ubuntu 18.04.3 LTS (Bionic Beaver)
      CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
      Memory: 482.58 MB / 11.63 GB
      Shell: 5.4.2 - /bin/zsh
    Binaries:
      Node: 8.10.0 - /usr/bin/node
      Yarn: 1.17.3 - /usr/bin/yarn
      npm: 3.5.2 - /usr/bin/npm
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.8 => 0.59.8 
    npmGlobalPackages:
      react-native-cli: 2.0.1

Same issue. Any solution ?

@mrbrentkelly
Copy link
Contributor

I'm getting same issue for a bunch of things after upgrading to 0.61.0 (from 0.59.10) including Alert, Dimensions, Platform.

To workaround it I've started mocking react-native itself and then mock whichever named export I need...

// From
jest.mock('Platform', () => ({
    OS: 'someOS'
}));

// To
jest.mock('react-native', () => ({
  Platform: {
    OS: 'someOS'
  }
}));

Still think there's an issue here though as I'm able to reproduce on a fresh React Native project.

@iamrenejr
Copy link

I'm confused. 0.61 is supposed to not use haste anymore, right? This issue is caused by haste. Can you guys give a new sample repro (the one I provided before was for a pre-0.60 version)?

@robertLichtnow
Copy link

I was using version 0.60.0 and this bug as occurring.
Upgraded to the latest version as of now, which is 0.61.2 and things went smoothly.

robertLichtnow added a commit to natura-cosmeticos/natds-js that referenced this issue Oct 11, 2019
affects: @natds/mobile

Upgraded react native version due to bug on jest execution described here:

facebook/react-native#23943
robertLichtnow added a commit to natura-cosmeticos/natds-js that referenced this issue Oct 11, 2019
affects: @natds/mobile

Upgraded react native version due to bug on jest execution described here:

facebook/react-native#23943
@prospteam
Copy link

I have The Same Issue when i downgrade from 0.61 into 0.60

@jbcrestot
Copy link

FI : I came across this bug today, and it was because, I was importing a file that imported himeself React while not being in a react environment (but babel-node for a script execution).

@gguidotti
Copy link

In case someone's still facing this issue using RN < 0.60 (I'm using 0.59.10):

  • Be sure to remove the "preset": "react-native" from your package.json;
  • Create your jest.config.json and be sure to include "preset": "react-native" inside it. In my case I was trying to setup Enzyme and the enzyme-to-json serializer:
{
  "preset": "react-native",
  "setupFiles": [
    "<rootDir>/src/tests/setupTests.js"
  ],
  "snapshotSerializers": [
    "enzyme-to-json/serializer"
  ]
}
  • Inside setupTests.js I wrote the adapter configuration as shown in the Enzyme website:
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

Enzyme.configure({ adapter: new Adapter() })

You should now be able to test your components

@willgriffiths
Copy link

I'm using react-native (0.61) in a yarn workspaces monorepo.

My fix was to makes sure that jest maps all react-native imports to the version of react-native in our app (and not one from the monorepo root).

This can be done by adding a moduleNameMapper rule in jest.config.js:

module.exports = {
  preset: "react-native",
  moduleNameMapper: {
    "^react-native$": require.resolve("react-native")
  }
}

moduleNameMapper | jest docs

@emenjivar
Copy link

If you have jest.config.js file inside your root directory,
you should add preset: 'react-native', property to module.export

so It will look like:

jest.config.js

module.exports = {
	preset: 'react-native',
        ...
};

Thanks @alexander-mozolevsky, this work for me :)

@royalbhati
Copy link

royalbhati commented Feb 15, 2020

Changing metro.config.js to this helped me

const blacklist = require('metro-config/src/defaults/blacklist');

module.exports = {
  resolver: {
    blacklistRE: blacklist([
      /node_modules\/.*\/node_modules\/react-native\/.*/,
    ])
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
};

@radihuq
Copy link

radihuq commented Mar 16, 2020

If you're working with a monorepo and are using components from a common package, try adding this to the package.json of the common package:

"devDependencies": {
    ...
},
"private": true,
"workspaces": {
	"nohoist": [
		"react-native",
		"react-native/**",
		"react",
		"react/**"
	]
}

Then get rid of all node_modules and install everything again.

@KeiShadow
Copy link

Hello try downgrade nodejs like i did, now im using node 10.20.1 and working good πŸ‘

@JulianKingman
Copy link

Nothing worked :(
For me it's associated with a particular package, @shoutem/ui. I'll cross-post an issue there.

@ghasemikasra39
Copy link

same here

@facebook facebook locked as resolved and limited conversation to collaborators Jun 21, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jun 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests