0

Describe If I add 2 or more web parts with mgt on the same page, the first web part is loaded correctly but the second and so on get an error: "Failed to execute 'define' on 'CustomElementRegistry': the name "mgt-person" has already been used with this registry".

Already tried:

gulp clean

delete node_modules and then npm i

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

To Reproduce Add 2 web parts in the same page with mgt and both with:

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

onInit()

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

render()

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

Full Error

[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

1 Answers1

0

This is a bug in the toolkit - it looks like each web part is trying to define the custom element and the second one fails since it's already defined. Tracking this issue here: https://github.com/microsoftgraph/microsoft-graph-toolkit/issues/229

Nikola Metulev
  • 566
  • 3
  • 7