0

描述 如果我在同一页面上添加 2 个或多个带有 mgt 的 Web 部件,则第一个 Web 部件加载正确,但第二个等出现错误:“无法在 'CustomElementRegistry' 上执行 'define':名称“mgt-人”已与此注册表一起使用”。

已经尝试过:

吞咽干净

删除 node_modules 然后 npm i

import {Providers, SharePointProvider} from '@microsoft/mgt/dist/commonjs';

重现 使用 mgt 在同一页面中添加 2 个 Web 部件,并且两者都使用:

import {Providers, SharePointProvider} from '@microsoft/mgt';

onInit()

protected async onInit(){
Providers.globalProvider = new SharePointProvider(this.context);
}

使成为()

public render(): void {
this.domElement.innerHTML = '
<mgt-agenda group-by-day days="7"></mgt-agenda>
';
}

完全错误

[SPLoaderError.loadComponentError]:
Failed to load component "801ae551-a013-4830-a775-6c05b1cc7f9c" (WpTestWebPart). Original error: Failed to load entry point from component "801ae551-a013-4830-a775-6c05b1cc7f9c" (WpTestWebPart). Original error: Failed to execute 'define' on 'CustomElementRegistry': the name "mgt-person" has already been used with this registry

INNERERROR:
Failed to load entry point from component "801ae551-a013-4830-a775-6c05b1cc7f9c" (WpTestWebPart). Original error: Failed to execute 'define' on 'CustomElementRegistry': the name "mgt-person" has already been used with this registry
CALLSTACK:
Error
    at t [as constructor] (https://spoprod-a.akamaihd.net/files/sp-client/sp-pages-assembly_es_01ffa67a4e201c116135624432aed4cf.js:4:53651)
    at new t (https://spoprod-a.akamaihd.net/files/sp-client/sp-pages-assembly_es_01ffa67a4e201c116135624432aed4cf.js:20:118840)
    at Function.e.buildErrorWithVerboseLog (https://spoprod-a.akamaihd.net/files/sp-client/sp-pages-assembly_es_01ffa67a4e201c116135624432aed4cf.js:20:128531)
    at Function.e.buildLoadComponentError (https://spoprod-a.akamaihd.net/files/sp-client/sp-pages-assembly_es_01ffa67a4e201c116135624432aed4cf.js:20:124562)
    at https://spoprod-a.akamaihd.net/files/sp-client/sp-pages-assembly_es_01ffa67a4e201c116135624432aed4cf.js:20:115054
4

1 回答 1

0

这是工具包中的一个错误 - 看起来每个 Web 部件都在尝试定义自定义元素,而第二个 Web 部件由于已经定义而失败。在此处跟踪此问题:https ://github.com/microsoftgraph/microsoft-graph-toolkit/issues/229

于 2019-12-04T22:47:14.540 回答