React Native 无法安装或运行expo

8yoxcaq7  于 2023-06-24  发布在  React
关注(0)|答案(1)|浏览(159)

我正在使用macOS Ventura 13.1
我无法安装Expo。每次输入npm install -g expo-cli命令时,都会出现以下错误:

npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/expo-cli
npm ERR! dest /usr/local/lib/node_modules/.expo-cli-dKBr48UN
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/expo-cli' -> '/usr/local/lib/node_modules/.expo-cli-dKBr48UN'
npm ERR!  [Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/expo-cli' -> '/usr/local/lib/node_modules/.expo-cli-dKBr48UN'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/usr/local/lib/node_modules/expo-cli',
npm ERR!   dest: '/usr/local/lib/node_modules/.expo-cli-dKBr48UN'
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: /Users/***/.npm/_logs/2023-06-19T18_30_12_325Z-debug-0.log

我尝试通过执行sudo npm install -g expo-cli来解决这个问题。这似乎允许我下载它只有警告。但是,当我稍后进入正确的文件夹并尝试运行npx expo startnpm start时,我得到以下错误:

WARNING: The legacy expo-cli does not support Node +17. Migrate to the new local Expo CLI: https://blog.expo.dev/the-new-expo-cli-f4250d8e3421.
Starting project at /Users/*****/ReactNativeCourse/WeatherApp
Unable to find expo in this project - have you run yarn / npm install yet?

之后,当我运行npm install试图解决这个问题时,我得到了另一个类似于上面的错误。

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: weatherapp@1.0.0
npm ERR! Found: react@undefined
npm ERR! node_modules/react
npm ERR!   react@"18.2.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"18.2.0" from react-native@0.71.8
npm ERR! node_modules/react-native
npm ERR!   react-native@"0.71.8" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! 
npm ERR! For a full report see:
npm ERR! /Users/williamwu/.npm/_logs/2023-06-19T18_43_08_612Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /Users/*****/.npm/_logs/2023-06-19T18_43_08_612Z-debug-0.log
vpfxa7rd

vpfxa7rd1#

经过几个小时的故障排除,我终于弄清楚了。我需要运行命令sudo chown -R 501:20 "/Users/Whatevernameyouhave/.npm"之后,使用expo init projectName创建项目。
另外,在安装expo时,请尝试使用此命令代替sudo npm i -g expo-cli
我尝试过的其他方法虽然不起作用,但可能对你有用:
我手动卸载了nodejs并重新安装了它。
我卸载并重新安装了vscode。
我卸载并重新安装世博会。

相关问题