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

创建React应用时遭遇循环依赖警告,求解决方案

解决npx create-my-app执行时的循环依赖属性访问警告

问题复现

执行命令:

npx create-my-app app

出现大量类似如下的警告:

(node:2056) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2056) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency
...

解决方案

这些警告的核心原因是依赖的shelljs包版本与当前Node.js版本不兼容,旧版shelljs的导出逻辑在Node 16+版本中会触发循环依赖与属性访问警告。尝试以下步骤解决:

  • 清除npm全局缓存

    npm cache clean --force
    
  • 若曾全局安装过create-my-app(或create-react-app,可能为笔误),先卸载全局包

    npm uninstall -g create-my-app
    
  • 使用最新版包创建应用

    npx create-my-app@latest app
    
  • 若警告仍存在,手动锁定shelljs兼容版本:

    1. 在项目根目录的package.json中添加resolutions字段(需npm 7+或Yarn支持):
    "resolutions": {
      "shelljs": "^0.8.5"
    }
    
    1. 重新安装依赖:
    npm install
    
  • 确保使用Node.js LTS版本(如18.x、20.x),避免版本兼容性问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 11:42:12