React-native:看起来你在全球范围内安装了react-native

问题描述 投票:4回答:2

当全局安装时,似乎存在react-native的错误。我需要它正确执行而不会看到此错误:

$ react-native run-ios
Looks like you installed react-native globally, maybe you meant react-native-cli?
To fix the issue, run:
npm uninstall -g react-native
npm install -g react-native-cli

在其他论坛上发布的解决方案对我不起作用,我不明白为什么这不起作用的原因。

package.json

{
  "name": "react-native-svgkit",
  "version": "0.2.2",
  "main": "Svg.js",
  "description": "A <Svg /> element for react-native that renders Svg images using SVGKit",
  "author": "Brent Vatne <[email protected]> (https://github.com/brentvatne)",
  "peerDependencies": {
    "react": "15.1.0",
    "react-native": ">=0.4.4"
  },
  "devDependencies": {
    "react-native": ">=0.4.4",
    "react-native-cli": "^0.1.10"
  },
  "dependencies": {
    "d3": "^3.5.5",
    "jsdom-jscore": "^0.1.0",
    "react-native-svg": "^2.2.0"
  },
  "repository": {
    "type": "git",
    "url": "[email protected]:brentvatne/react-native-svgkit.git"
  },
  "scripts": {
    "start": "node /usr/local/lib/node_modules/react-native/local-cli/cli.js start"
  }
}
node.js reactjs npm react-native npm-install
2个回答
3
投票

在我的情况下,这个问题是因为因为npm是使用自制软件安装的。有关此问题的说明以及如何解决此问题,请访问this gist。总之,所需的修复是卸载所有npm全球安装的软件包,卸载节点,然后重新安装节点,并重新安装没有brew的npm。

npm list -g --depth=0 # to list all your globally installed packages
rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh

然后,您必须重新安装使用npm install -g <package_name>全局安装的所有npm软件包。

不幸的是,当我重新启动机器时,同样的问题又重新出现了。我目前的工作是遵循here的建议,即

npm install --save-dev react-native-cli

有关正在发生的事情的任何解释都是受欢迎的。


0
投票

在package.json中使用它

"scripts": {
   "android": "node node_modules/react-native/local-cli/cli.js run-android"
}

代替

"scripts": {
    "android": "react-native run-android"
 }
© www.soinside.com 2019 - 2024. All rights reserved.