React-native:看起来你全局安装了 react-native

Pet*_* G. 9 node.js npm reactjs react-native npm-install

全局安装时,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
Run Code Online (Sandbox Code Playgroud)

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

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 <brentvatne@gmail.com> (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": "git@github.com:brentvatne/react-native-svgkit.git"
  },
  "scripts": {
    "start": "node /usr/local/lib/node_modules/react-native/local-cli/cli.js start"
  }
}
Run Code Online (Sandbox Code Playgroud)

小智 6

在 package.json 中使用它

"scripts": {
   "android": "node node_modules/react-native/local-cli/cli.js run-android"
}
Run Code Online (Sandbox Code Playgroud)

代替

"scripts": {
    "android": "react-native run-android"
 }
Run Code Online (Sandbox Code Playgroud)


Obr*_*ios 3

就我而言,这个问题是因为 npm 是使用自制软件安装的。有关此问题的描述以及如何解决此问题可以在this gist中找到。总之,所需的修复是卸载所有 npm 全局安装的软件包,卸载 Node,然后重新安装 Node,并在不使用 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
Run Code Online (Sandbox Code Playgroud)

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

不幸的是,当我重新启动机器时,同样的问题再次出现。我目前的解决方法是遵循此处的建议,即

npm install --save-dev react-native-cli
Run Code Online (Sandbox Code Playgroud)

欢迎对正在发生的事情进行任何解释。