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

Nuxt 3中执行ShadcnVue组件添加命令时遇components.json无效错误

解决 shadcn-vue 添加组件时的 components.json 无效问题

问题场景

执行命令 npx shadcn-vue@latest add toast 时触发错误提示:

[5:28:37 PM] An invalid components.json file was found at /Users/****/Projects/****.
Before you can add components, you must create a valid components.json file by running the init command.
[5:28:37 PM] Learn more at https://shadcn-vue.com/docs/components-json.

解决步骤

  • 先在项目根目录执行初始化命令,生成合规的 components.json 配置文件:
    npx shadcn-vue@latest init
    
  • 初始化过程中会提示配置组件存储路径、样式方案等选项,按需完成配置后,重新执行添加组件的命令即可:
    npx shadcn-vue@latest add toast
    

原因说明

当前项目中的 components.json 文件格式无效或缺少必要配置项,shadcn-vue 依赖该文件管理组件的安装逻辑与配置信息,因此必须先通过 init 命令生成合法的配置文件才能继续添加组件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 04:24:51