You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行yarn start时遭遇spawn ENOTDIR错误求解决方案

问题:使用yarn start启动Expo项目时出现ENOTDIR错误

每次执行yarn start都会抛出以下错误:

node:internal/errors:490
ErrorCaptureStackTrace(err);
^

Error: spawn ENOTDIR
at ChildProcess.spawn (node:internal/child_process:413:11)
at Object.spawn (node:child_process:757:9)
at spawn (/Users/ni/Desktop/WORK/RET/LEAING/ToGo/.yarn/cache/cross-spawn-npm-6.0.5-2deab6c280-f893bb0d96.zip/node_modules/cross-spawn/index.js:12:24)
at run (/Users/ni/Desktop/WORK/RET/LEAING/ToGo/.yarn/unplugged/expo-npm-47.0.13-9da3537782/node_modules/expo/bin/cli.js:11:12)
at Object. (/Users/ni/Desktop/WORK/RET/LEAING/ToGo/.yarn/unplugged/expo-npm-47.0.13-9da3537782/node_modules/expo/bin/cli.js:6:1)
at Module._compile (node:internal/modules/cjs/loader:1226:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
at require$$0.Module._extensions..js (/Users/ni/Desktop/WORK/RET/LEAING/ToGo//.pnp.cjs:21020:33)
at Module.load (node:internal/modules/cjs/loader:1089:32)
at require$$0.Module._load
(/Users/ni/Desktop/WORK/RET/LEAING/ToGo//.pnp.cjs:20839:22) {
errno: -20,
code: 'ENOTDIR',
syscall: 'spawn'
}

环境版本

  • Node.js: v18.14.0
  • npm: 9.4.1
  • Yarn: 3.4.1
  • Expo CLI: 6.3.0(提示:legacy expo-cli不支持Node +17,需迁移到版本化Expo CLI npx expo)
  • React Native: 0.71

注:使用npx create-expo-app AwesomeProject通过npm可正常运行,但希望用Yarn操作。


解决方案

1. 迁移到版本化Expo CLI(推荐)

Legacy Expo CLI不支持Node 17+,这是核心问题之一。执行以下命令切换到新版本:

yarn global remove expo-cli
yarn add -D expo

之后用yarn expo start代替yarn start启动项目。

2. 禁用Yarn PnP模式

Yarn 3的PnP模式可能与部分Expo依赖冲突,尝试切换回传统node_modules模式:

  • 在项目根目录创建或修改.yarnrc.yml,添加:
    nodeLinker: node-modules
    
  • 执行yarn install重新安装依赖,再运行yarn start。

3. 清理缓存并重装依赖

yarn cache clean
rm -rf node_modules
rm yarn.lock
yarn install

完成后尝试启动项目。

4. 用Yarn直接创建新项目

如果现有项目问题无法解决,直接用Yarn初始化Expo项目:

yarn create expo-app AwesomeProject
cd AwesomeProject
yarn expo start

内容的提问来源于stack exchange,提问作者NITHISH K MEGARAJAN

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 01:01:18