我已经安装了 Nodejs、Java、Python 和 android studio,并按照以下命令安装了 create-react-native-app
npm install -g create-react-native-app
之后我就跑
sudo create-react-native-app MyFirstNative
但出现错误
我已经更新了 npm、expo-cli 等,甚至使用 sudo 命令也会出现权限错误
azad@azadhussain:/var/www/html/githubrepo$ sudo create-react-native-app MyFirstNative
┌─────────────────────────────────────────────────────────────┐
│ │
│ There is a new version of expo-cli available (2.17.2). │
│ You are currently using expo-cli 2.17.1 │
│ Run `npm install -g expo-cli` to get the latest version │
│ │
└─────────────────────────────────────────────────────────────┘
? Choose a template: expo-template-tabs
✔ Please enter a few initial configuration values.
Read more: https://docs.expo.io/versions/latest/workflow/configuration/ · 100% completed
Extracting project files...
Customizing project...
Initialized a git repository.
Installing dependencies...
npm WARN deprecated [email protected]: core-js@<2.6.5 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
npm WARN deprecated [email protected]: Please upgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visit <https://github.com/lukeed/kleur/releases/tag/v3.0.0\> for migration path(s).
npm WARN deprecated [email protected]: use String.prototype.padStart()
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://[email protected]/expo/react-native-maps.git
npm ERR!
npm ERR! fatal: failed to stat '/var/www/html/githubrepo/MyFirstNative': Permission denied
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /home/azad/.npm/_logs/2019-05-14T04_30_21_275Z-debug.log
npm exited with non-zero code: 1
Set EXPO_DEBUG=true in your env to view the stack trace.
azad@azadhussain:/var/www/html/githubrepo$ ```
[Screenshot][1]
[1]: https://i.stack.imgur.com/9UCuo.png
答案1
我通过更改 .npm 目录的权限解决了这个问题。我进入了 npm 全局目录,它位于
/home/<user-name>
我通过输入此命令进入了该目录
cd /home/<user-name>
然后通过输入此命令更改.npm 文件夹的权限。
sudo chmod -R 777 ".npm"
对我来说,这个方法非常有效。但是,这种方法存在安全漏洞,也就是说,你的全局包目录可供所有层级访问。
答案2
对我自己来说,这是因为我使用的是旧版本的 Node(v8.11.3),而稳定版本(截至目前)是 v14.15.4。
我的解决方法是通过下载最新的稳定版本来更新 Node。