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

React项目切换至yarn后无法安装redux类包,求排查配置问题

问题:Yarn安装Redux相关包失败,提示找不到包

我将React项目的包管理器从npm切换为yarn后,执行yarn add redux、yarn add react-redux等安装命令均失败,报错信息如下:

yarn add v1.22.19
[1/4] 🔍  Resolving packages...
error Couldn't find package "react-redux" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

执行yarn config list得到的配置输出为:

yarn config v1.22.19
info yarn config
{
  'version-tag-prefix': 'v',
  'version-git-tag': true,
  'version-commit-hooks': true,
  'version-git-sign': false,
  'version-git-message': 'v%s',
  'init-version': '1.0.0',
  'init-license': 'MIT',
  'save-prefix': '^',
  'bin-links': true,
  'ignore-scripts': false,
  'ignore-optional': false,
  registry: 'https://registry.yarnpkg.com',
  'strict-ssl': false,
  'user-agent': 'yarn/1.22.19 npm/? node/v16.17.1 darwin arm64',
  lastUpdateCheck: 1690739349194
}

请问我的yarn配置是否存在问题?


解决方案

从配置和报错信息来看,存在registry配置不匹配的问题:配置里显示使用yarn官方源,但报错提示在npm源找不到包,可能是配置未生效或网络访问异常。可以按以下步骤排查修复:

  • 切换到npm官方源:
    yarn config set registry https://registry.npmjs.org/
    
  • 验证配置是否更新:
    yarn config list
    
  • 重新执行安装命令:
    yarn add redux react-redux
    
  • 若仍失败,清除yarn缓存后重试:
    yarn cache clean
    

内容的提问来源于stack exchange,提问作者Victor Cui

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 09:01:09