Forum Discussion
Stephan E.
Apr 26, 2018Copper Contributor
SharePointFramework: unable to load main WebPart component when it contains code to load jQuery
the render method In my main WebPart ts file looks like this: public render(): void {
if (this.renderedOnce === false) {
ModuleLoader.loadScript('https://code.jquery.com/jquery-2.1.1...
Gautam Sheth
Apr 27, 2018Copper Contributor
You are using ModuleLoader which has been long deprecated.
Instead of that you should be using SPComponentLoader
Add the below import statement:
import { SPComponentLoader } from '@microsoft/sp-loader';
And modify your code to:
SPComponentLoader.loadScript('https://code.jquery.com/jquery-2.1.1.min.js', { globalExportsName: 'jQuery' }).then(($: any): void => {
this.jQuery = $;
SPComponentLoader.loadScript('https://code.jquery.com/ui/1.12.1/jquery-ui.min.js', { globalExportsName: 'jQuery' }).then((): void => {
this.renderContents();
});
});
Stephan E.
Apr 27, 2018Copper Contributor
Thank you! I did not test your solution though. I meanwhile added jquery via npm and that works so far.