11
votes

Am trying out react-native and get below error, when I install and try to use react-navigation (import {StackNavigator} from 'react-navigation';).

Error

I use the following command to install "react-navigation" : npm install --save react-navigation

On running above command I get 'react-navigation' folder under node_modules folder, with just a single file (package.json). Below is the content of the file:

{
  "_args": [
    [
      {
        "raw": "[email protected]",
        "scope": null,
        "escapedName": "react-navigation",
        "name": "react-navigation",
        "rawSpec": "0.0.0",
        "spec": "0.0.0",
        "type": "version"
      },
      "/Users/rakesh-1812/Documents/REACT_JS/SimpleApp"
    ]
  ],
  "_from": "[email protected]",
  "_id": "[email protected]",
  "_inCache": true,
  "_location": "/react-navigation",
  "_nodeVersion": "4.2.1",
  "_npmOperationalInternal": {
    "host": "packages-12-west.internal.npmjs.com",
    "tmp": "tmp/react-navigation-0.0.0.tgz_1459892254509_0.1584461957681924"
  },
  "_npmUser": {
    "name": "ericvicenti",
    "email": "[email protected]"
  },
  "_npmVersion": "2.14.7",
  "_phantomChildren": {},
  "_requested": {
    "raw": "[email protected]",
    "scope": null,
    "escapedName": "react-navigation",
    "name": "react-navigation",
    "rawSpec": "0.0.0",
    "spec": "0.0.0",
    "type": "version"
  },
  "_requiredBy": [
    "#USER",
    "/"
  ],
  "_resolved": "https://registry.npmjs.org/react-navigation/-/react-navigation-0.0.0.tgz",
  "_shasum": "1e0f865235cdb4d4aa8086484fd3690ff73df553",
  "_shrinkwrap": null,
  "_spec": "[email protected]",
  "_where": "/Users/rakesh-1812/Documents/REACT_JS/SimpleApp",
  "dependencies": {},
  "description": "Coming Soon",
  "devDependencies": {},
  "directories": {},
  "dist": {
    "shasum": "1e0f865235cdb4d4aa8086484fd3690ff73df553",
    "tarball": "https://registry.npmjs.org/react-navigation/-/react-navigation-0.0.0.tgz"
  },
  "maintainers": [
    {
      "name": "ericvicenti",
      "email": "[email protected]"
    }
  ],
  "name": "react-navigation",
  "optionalDependencies": {},
  "readme": "ERROR: No README data found!",
  "scripts": {},
  "version": "0.0.0"
}

Can someone please help me resolve the issue. Thanks in advance.

4
can i see your project's package.json - Codesingh
You need to restart your packager every time you add a new library, usually this is the most common issue with that error. - Matt Aft
@Codesingh Below is my project's package.json { "name": "SimpleApp", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "react": "15.4.2", "react-native": "^0.42.3", "react-navigation": "0.0.0" }, "devDependencies": { "babel-jest": "19.0.0", "babel-preset-react-native": "1.9.1", "jest": "19.0.2", "react-test-renderer": "15.4.2" }, "jest": { "preset": "react-native" } } - Rakesh Krishna
The react-navigation module has not installed properly. I would try deleting the node_modules folder, remove the "react-navigation": "0.0.0" from your package.json, and run npm install and npm install --save react-navigation again. - Alan

4 Answers

16
votes

React navigation is still in beta. It works for me when I use the command:

npm install --save [email protected] 

This is the latest release. https://github.com/react-community/react-navigation/releases

7
votes

You must stop your node server and start it again.

Do it:

sudo lsof -n -i4TCP:8081 | grep LISTEN

It will listen of the services that are running on port 8081. By default, react native server runs on it. Then, execute the command below to kill the server process.

kill -9 <cma process id>

Finally, run your project again with

react-native run-ios 

on the project folder

1
votes

I was unable to install react-native, tried everything from the internet. Using Yarn instead of npm resolved the problem.

0
votes

Try installing react-navigation stack, npm i react-navigation-stack. Then import {createStackNavigator} from 'react-navigation-stack'

Stop the server and run your project again.