Amplify-js: Unable to resolve module @react-native-community/netinfo from node_modules\@aws-amplify\core\lib\Util\Reachability.native.js

Created on 29 Feb 2020  路  7Comments  路  Source: aws-amplify/amplify-js

Describe the bug
I upgraded to [email protected] today. My app stopped working with the error Unable to resolve module @react-native-community/netinfo from node_modules\@aws-amplify\core\lib\Util\Reachability.native.js

To Reproduce

  • Create react native app: npx react-native init Amplify226
  • Initialize Amplify: amplify init
  • Install aws-amplify: npm install aws-amplify
  • Edit index.js
import Amplify from 'aws-amplify';
import config from './aws-exports';
Amplify.configure(config);
  • Run Android app: npx react-native run-android
error: bundling failed: Error: Unable to resolve module `@react-native-community/netinfo` from `node_modules\@aws-amplify\core\lib\Util\Reachability.native.js`: @react-native-community/netinfo could not be found within the project.

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules: rm -rf node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
    at ModuleResolver.resolveDependency (C:\Users\Daniel\Documents\medtech\Amplify226\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:186:15)
    at ResolutionRequest.resolveDependency (C:\Users\Daniel\Documents\medtech\Amplify226\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (C:\Users\Daniel\Documents\medtech\Amplify226\node_modules\metro\src\node-haste\DependencyGraph.js:282:16)
    at Object.resolve (C:\Users\Daniel\Documents\medtech\Amplify226\node_modules\metro\src\lib\transformHelpers.js:267:42)
    at C:\Users\Daniel\Documents\medtech\Amplify226\node_modules\metro\src\DeltaBundler\traverseDependencies.js:426:31
    at Array.map (<anonymous>)
    at resolveDependencies (C:\Users\Daniel\Documents\medtech\Amplify226\node_modules\metro\src\DeltaBundler\traverseDependencies.js:423:18)
    at C:\Users\Daniel\Documents\medtech\Amplify226\node_modules\metro\src\DeltaBundler\traverseDependencies.js:275:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (C:\Users\Daniel\Documents\medtech\Amplify226\node_modules\metro\src\DeltaBundler\traverseDependencies.js:87:24)


Environment

  System:
    OS: Windows 10 10.0.18363
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
    Memory: 2.10 GB / 7.85 GB
  Binaries:
    Node: 13.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.13.7 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    aws-amplify: ^2.2.6 => 2.2.6
    babel-jest: ^24.9.0 => 24.9.0
    eslint: ^6.5.1 => 6.8.0
    jest: ^24.9.0 => 24.9.0
    metro-react-native-babel-preset: ^0.56.0 => 0.56.4
    react: 16.9.0 => 16.9.0
    react-native: 0.61.5 => 0.61.5
    react-test-renderer: 16.9.0 => 16.9.0

to-be-reproduced

Most helpful comment

Yes, if I manually install that dependency with npm install @react-native-community/netinfo, I can run the app.

All 7 comments

Hi @dantasfiles, could you please try the following steps:

yarn add @react-native-community/netinfo
react-native link @react-native-community/netinfo

@dantasfiles if using React Native 0.60 or above, you do not need to run the link step.
Do:

yarn add @react-native-community/netinfo

And then nothing else for android.
For ios on RN 0.60+ do:

cd ios && pod install && cd ..

If you are using React Native <0.60 then or want more details look here:
https://github.com/react-native-community/react-native-netinfo#getting-started

Yes, if I manually install that dependency with npm install @react-native-community/netinfo, I can run the app.

Glad you got it working @dantasfiles. Since the resolution steps worked for you, I'll go ahead and close the issue.

Kind suggestion: Is it possible to add this as a project dependency? I ran into the same issue and in my opinion, the package should have downloaded this additional dependency automatically

Why is this not a project dependency???

_At the very least_, you need to include the step of adding netinfo in your installation documentation...

I don't mean to re-open this issue. I just landed here after some research and thought it'd be good to circle back to some AWS documentation in case anyone else finds their way here.

Seems AWS heard, and they did add the dependencies to include in their documentation:
npm install aws-amplify aws-amplify-react-native @react-native-community/netinfo

https://docs.amplify.aws/start/getting-started/setup/q/integration/react-native#install-amplify-libraries

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cgarvis picture cgarvis  路  3Comments

josoroma picture josoroma  路  3Comments

callmekatootie picture callmekatootie  路  3Comments

lucasmike picture lucasmike  路  3Comments

guanzo picture guanzo  路  3Comments