jeecgboot/JeecgBoot · error
【addComponent】不能使用"${type}"作为组件的name,因为这是关键字。
Error message
【addComponent】不能使用"${type}"作为组件的name,因为这是关键字。 What it means
addComponent registers a JVxeTable cell component under a JVxeTypes key. A fixed list (excludeKeywords) contains reserved type names — hidden, rowNumber, rowCheckbox, rowRadio, rowExpand — that are internal system column types, not editable cells. Registering a custom component under one of these would shadow built-in behavior, so the guard rejects it. This is a programming-error guard, not a runtime data error.
Source
Thrown at jeecgboot-vue3/src/components/jeecg/JVxeTable/src/componentMap.ts:47
/** 定义不能用于注册的关键字 */
export const excludeKeywords: Array<JVxeTypes> = [
JVxeTypes.hidden,
JVxeTypes.rowNumber,
JVxeTypes.rowCheckbox,
JVxeTypes.rowRadio,
JVxeTypes.rowExpand,
];
/**
* 注册组件
*
* @param type 组件 type
* @param component Vue组件
* @param spanComponent 显示组件,可空,默认为 JVxeNormalCell 组件
*/
export function addComponent(type: JVxeTypes, component: JVxeVueComponent, spanComponent?: JVxeVueComponent) {
if (excludeKeywords.includes(type)) {
throw new Error(`【addComponent】不能使用"${type}"作为组件的name,因为这是关键字。`);
}
if (componentMap.has(type)) {
throw new Error(`【addComponent】组件"${type}"已存在`);
}
componentMap.set(type, component);
if (spanComponent) {
componentMap.set(type + spanEnds, spanComponent);
}
// 代码逻辑说明: 【issues/860】生成的一对多代码,热更新之后点击新增卡死[暂时先解决]
import.meta.env.DEV && (window[JVxeComponents] = componentMap);
}
export function deleteComponent(type: JVxeTypes) {
componentMap.delete(type);
componentMap.delete(type + spanEnds);
// 代码逻辑说明: 【issues/860】生成的一对多代码,热更新之后点击新增卡死[暂时先解决]
import.meta.env.DEV && (window[JVxeComponents] = componentMap);
}View on GitHub (pinned to 96fb33f5ec)
Solutions
- Choose a non-reserved JVxeTypes value (or add a new entry to the enum) for your custom component.
- Check the excludeKeywords list before calling addComponent and skip reserved names.
- If extending the enum, do not reuse hidden/rowNumber/rowCheckbox/rowRadio/rowExpand names.
Example fix
// before addComponent(JVxeTypes.rowNumber, MyCell); // reserved keyword, throws // after — use a custom, non-reserved type addComponent(JVxeTypes.myCustomType, MyCell);
Defensive patterns
Strategy: validation
Validate before calling
import { excludeKeywords } from './componentMap';
function safeAddComponent(type, component, spanComponent?) {
if (excludeKeywords.includes(type)) {
console.warn(`Skipping reserved type ${type}`);
return;
}
addComponent(type, component, spanComponent);
} Type guard
const isReservedType = (t: JVxeTypes): boolean => excludeKeywords.includes(t);
Try / catch
try {
addComponent(type, component);
} catch (e) {
// type is reserved; choose another name
} Prevention
- Check excludeKeywords before registering custom cell types.
- Add new types to the JVxeTypes enum instead of reusing reserved names.
- Write a unit test asserting your registrations avoid reserved names.
When it happens
Trigger: Calling addComponent(JVxeTypes.rowNumber, myComponent) or passing any of the five reserved JVxeTypes values as the first argument during third-party component registration (typically in registerThirdComp.ts or an app plugin).
Common situations: Building a custom JVxeTable plugin and accidentally choosing a type name that collides with a built-in; copy-pasting a registration block and forgetting to change the type; iterating over all JVxeTypes enum values to auto-register.
Related errors
- 【addComponent】组件"${type}"已存在
- [JVxeTable] ${$type} 组件尚未注册,获取增强失败
- useDescription() can only be used inside setup() or function
- useTableContext must be used after createTableContext
- sys.api.apiRequestFailed
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/a4578186cea509bb.
Report an issue: GitHub.