Get error when import any dependency with React Native

After init a React Native project, if i install and import any other dependency, it will show this error message after run "react-native run-ios":

Error Message with react-native run-ios

For e.g: I run "react-native init RNProject" to create simple react native project. After that i install react-navigation by :"npm install --save-dev react-navigation" then i import createStackNavigator by "import { createStackNavigator } from 'react-navigation';" in App.js and do nothing. After run "react-native run-ios" and got that error above. Remove the "import { createStackNavigator } from 'react-navigation';" will cause the app run normally.

I tried "rm node_modules/react-native/local-cli/core/fixtures/files/package.json" or "rm ./node_modules/react-native/local-cli/core/fixtures/files/package.json" but the terminal show "No such file or directory".

My Environment

| software         | version
| ---------------- | -------
| react-navigation | 2.6.2
| react-native     | 0.56.0
| node             | 8.11.3
| npm              | 5.3.0
| MacOS            | 10.13.5

3 answers

  • answered 2018-07-11 04:39 zohreh

    seem it could not install react-navigation.maybe you have problem with network . try again npm install --save react-navigation and look inside of react-native folder for react-navigation folder.if it dont exist therefore it didnt install.you should find out what is problem with install. in additional you should run react-native link after installing any library.

  • answered 2018-07-11 05:39 Mahdi Bashirpour

    I had such a problem.

    Change version react-native => 0.55.0

    And then => npm install

  • answered 2018-07-11 05:46 Revansiddh

    Problem:

    Because you used --save-dev in install cmd which means it will be installed as devDependencies in your project.

    Solution: Try just installing with this npm install --save react-navigation which will install it as dependencies;

    Look at you package.json if you find react-navigation this in dependencies section and still find same problem try deleting node_modules and npm i