【问题标题】:Unable to update or execute the 'expo' command in command prompt无法在命令提示符下更新或执行“expo”命令
【发布时间】:2025-12-30 13:40:12
【问题描述】:

我第一次尝试在我的项目目录上安装 expo-cli,它工作正常。我可以使用expo init 在我的命令提示符中创建我的第一个反应本机应用程序,并使用expo start 运行该应用程序。但是现在当我有一些新项目要使用“expo”命令(如expo initexpo start 或其他东西)时,它不再起作用了。当我尝试键入并输入 expo 命令时,它总是 'expo' is not recognized as an internal or external command, operable program or batch file.

现在,当我尝试使用 npm install -g expo-cli 更新 expo-cli 时,出现了错误警告。

npm ERR! code EPERM
npm ERR! syscall rename
npm ERR! path C:\Users\ACER\AppData\Roaming\npm\node_modules\expo-cli
npm ERR! dest C:\Users\ACER\AppData\Roaming\npm\node_modules\.expo-cli-foqoNR8w
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, rename 'C:\Users\ACER\AppData\Roaming\npm\node_modules\expo-cli' -> 'C:\Users\ACER\AppData\Roaming\npm\node_modules\.expo-cli-foqoNR8w'
npm ERR!  [Error: EPERM: operation not permitted, rename 'C:\Users\ACER\AppData\Roaming\npm\node_modules\expo-cli' -> 'C:\Users\ACER\AppData\Roaming\npm\node_modules\.expo-cli-foqoNR8w'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'rename',
npm ERR!   path: 'C:\\Users\\ACER\\AppData\\Roaming\\npm\\node_modules\\expo-cli',
npm ERR!   dest: 'C:\\Users\\ACER\\AppData\\Roaming\\npm\\node_modules\\.expo-cli-foqoNR8w'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
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!     C:\Users\ACER\AppData\Local\npm-cache\_logs\2021-01-10T17_18_03_575Z-debug.log

这使我无法安装反应导航并使用“expo”命令创建一个新项目。我一直在搜索这个问题并试图解决它,但它在我尝试过的任何各种方式上都不起作用。我尝试重新安装 expo-cli 但它不起作用,我也尝试使用 yarn 但它仍然不起作用。我已经重新添加了 npm 的路径,甚至尝试重新安装 nodejs 并使用任何各种代码来更新和安装“expo-cli”,但它没有按预期工作。

有什么建议可以解决这个问题吗?

【问题讨论】:

  • Error: EPERM: operation not permitted,看来您需要以管理员权限运行命令提示符。
  • 我之前尝试过(以管理员身份运行),但仍然是一个错误

标签: npm npm-install expo


【解决方案1】:

以管理员身份运行命令行,然后执行以下操作:

npm remove -g expo-cli 删除现有的 CLI 然后npm i -g expo-cli 重新安装 Expo CLI。

然后您只需通过expo login 登录(如果您已登录)并从您所在的位置起飞!

【讨论】:

  • 当我尝试运行命令 npm remove -g expo-cli 时,我仍然遇到了一个错误,就像我问之前一样,npm i -g expo-cli 也是如此。当我尝试运行expo login --> 'expo' 不被识别为内部或外部命令、可运行程序或批处理文件时。`
【解决方案2】:

我删除了路径上的expo文件:

C:\Users\ACER\AppData\Roaming\npm\node_modules\expo-cli
C:\Users\ACER\AppData\Roaming\npm\node_modules\.expo-cli-foqoNR8w

我删除的文件: expo-cli & .expo-cli-foqoNR8w

然后尝试使用npm install --global expo-cli 再次安装expo-cli,然后它就可以工作了。现在我可以使用我的expo start 或任何带有“expo”的代码。而且现在我可以在我的项目目录上安装反应导航。我正在使用以管理员身份运行的命令提示符运行安装。

【讨论】: