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

使用Yarn创建React项目异常:缺失核心文件且安装未完成

使用Yarn创建React项目时核心文件缺失的问题

问题描述

使用Yarn创建React项目时出现异常,仅生成node_modules和package.json文件,未创建src目录、.gitignore等核心文件,与预期的项目结构不符。

执行命令及日志

PS C:\Users\ANAS> yarn create react-app fresh-app2
yarn create v1.22.19
[1/4] 解析包...
[2/4] 获取包...
[3/4] 链接依赖项...
[4/4] 构建新包...
success Installed "create-react-app@5.0.1" with binaries:
      - create-react-app

正在 C:\Users\ANAS\fresh-app2 创建新的 React 应用。

正在安装包,这可能需要几分钟时间。
正在安装 react、react-dom 和 react-scripts 以及 cra-template...

yarn add v1.22.19
info 未找到锁文件。
[1/4] 解析包...
warning react-scripts > @svgr/webpack > @svgr/plugin-svgo > svgo@1.3.2: 此 SVGO 版本不再受支持,请升级到 v2.x.x。
warning react-scripts > @svgr/webpack > @svgr/plugin-svgo > svgo > stable@0.1.8: 现代 JS 已保证 Array#sort() 是稳定排序,因此该库已弃用。请查看 MDN 上的兼容性表格:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
warning react-scripts > css-minimizer-webpack-plugin > cssnano > cssnano-preset-default > postcss-svgo > svgo > stable@0.1.8: 现代 JS 已保证 Array#sort() 是稳定排序,因此该库已弃用。请查看 MDN 上的兼容性表格:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
warning react-scripts > jest > @jest/core > jest-config > jest-environment-jsdom > jsdom > w3c-hr-time@1.0.2: 使用平台原生的 performance.now() 和 performance.timeOrigin。
[2/4] 获取包...
[3/4] 链接依赖项...
warning "react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" 存在未满足的对等依赖 "@babel/plugin-syntax-flow@^7.14.5"。
warning "react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" 存在未满足的对等依赖 "@babel/plugin-transform-react-jsx@^7.14.9"。
warning "react-scripts > react-dev-utils > fork-ts-checker-webpack-plugin@6.5.2" 存在未满足的对等依赖 "typescript@>= 2.7"。
warning "react-scripts > eslint-config-react-app > @typescript-eslint/eslint-plugin > tsutils@3.21.0" 存在未满足的对等依赖 "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta"。
[4/4] 构建新包...
success 已保存锁文件。
success 已保存 761 个新依赖项。
info 直接依赖项
// 为精简内容,此处删除了依赖列表(与示例链接中的一致)
Done in 41.54s.

可行解决方案

  • 清理缓存重试:执行yarn cache clean清除Yarn缓存,删除已创建的fresh-app2目录后,重新运行yarn create react-app fresh-app2
  • 切换创建方式:使用官方推荐的npx create-react-app fresh-app2命令创建项目,规避Yarn版本兼容性问题
  • 升级Yarn版本:当前使用的Yarn版本为1.22.19,执行yarn set version stable升级到最新稳定版后重试
  • 手动补充文件:如果重试无效,可从官方React模板仓库手动复制.gitignore、src/目录等核心文件到项目中,确保package.json内的脚本命令正常可用

内容的提问来源于stack exchange,提问作者Anas TAHANI

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 04:55:24