Yasin

Yasin

npm 作用域包(scoped package)是什么

@ 开头是 npm 的**作用域包(Scoped Package)**命名规范。

为什么有 @ 开头

npm 包名有两种格式:

普通包:    react、lodash、axios
作用域包:  @react/core、@radix-ui/react-dialog、@agent-labs/agent-chat
           @组织名/包名

@组织名 用于将同一组织的多个包归组在一起,避免包名冲突。比如你项目里:

import { ... } from "@radix-ui/react-dialog"    // Radix UI 的 dialog 组件
import { ... } from "@radix-ui/react-tooltip"   // Radix UI 的 tooltip 组件
import { ... } from "@agent-labs/agent-chat"    // agent-labs 组织的 agent-chat 包
import { ... } from "@ag-ui/core"               // ag-ui 组织的 core 包

@/@xxx/ 的区别

import { cn } from "@/common/lib/utils"; // ← 这个 @ 不是作用域包!
import { Context } from "@agent-labs/agent-chat"; // ← 这个才是作用域包
  • @/ — 是 TypeScript 路径别名,@ 映射到 src/ 目录,相当于 ../../src/common/lib/utils,在 tsconfig.json 里配置
  • @xxx/yyy — 是 npm 作用域包,从 node_modules 里找

两者长得像但完全不同,区分方式:有斜杠 / 紧跟在 @ 后面的是路径别名,有组织名再加斜杠的是作用域包