2017-03-27 31 views
2

当我安装并尝试使用react-navigation(从'react-navigation'导入{StackNavigator})时,我尝试了react-native并得到了以下错误。无法解析'react-navigation'

Error

我用下面的命令来安装“反应导航”:NPM安装--save反应导航

在上面的命令运行我得到“反应导航”文件夹node_modules文件夹,只有一个文件(package.json)。以下是该文件的内容:

{ 
    "_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" 
} 

有人可以帮我解决问题。提前致谢。

+1

我可以看到您的项目的package.json – Codesingh

+2

每次添加新库时都需要重新启动打包程序,通常这是该错误最常见的问题。 –

+0

@Codesingh下面是我的项目的package.json { “名”: “SimpleApp”, “版本”: “0.0.1”, “私”:真实, “脚本”:{ “开始”:“节点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“ } } –

回答

2

您必须停止节点服务器并重新启动它。

做它:

sudo lsof -n -i4TCP:8081 | grep LISTEN 

它会听那些在端口8081上运行默认情况下,服务的,反应本地服务器上运行。然后,执行下面的命令来终止服务器进程。

kill -9 <cma process id> 

最后,在项目文件夹再次

react-native run-ios 

运行项目