首页 > 解决方案 > 如何在 macbook pro big sur 上安装 expo CLI?

问题描述

我在新 Mac 上安装 expo 时遇到问题。当我运行这个命令时:

npm install --global expo-cli

我有错误:

npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/theowatine/.npm/_logs/2020-11-21T09_26_14_033Z-debug.log

有谁知道可能是什么解决方案?谢谢您的帮助!

标签: iosreact-nativenpmexpo

解决方案


这是使用全局安装的npm. 该npm文档包含一个关于它的页面

他们建议使用版本管理器(如)重新安装node/ 。如果您在本地开发某些东西,这通常是一个非常好的选择。如果你这样做,这个问题就会消失。如果你愿意,你可以停止阅读这个答案。npmnvm

它们还提供了一种配置方式npm,将全局安装的项目放在您选择的目录中。如果版本管理器出于某种原因无法为您工作,这也是一个不错的选择。

他们提到的另一个选择是使用npx而不是全局安装该工具。我经常使用这个并且非常喜欢它,但这确实意味着您经常必须记住在看到的命令前加上npx.

他们没有列出两个比较常见的选项。一种是使用sudo. 这意味着任何生命周期脚本都将在您的机器上以 root 身份运行。这通常是一个坏主意(这就是他们在文档中没有提到它的原因),但很常见。

另一种选择是chmod您的/usr/local/lib/node_modules目录,以便您可以写入它。在我看来,这也不是一个好主意(这可能是文档中也没有提到它的原因),但人们会这样做。

expo-cli大多数本地开发的情况下,使用包管理器安装nvm可能是要走的路。


推荐阅读