SPFX Placerholder/Header (Application Extension)
Category
- [x] Question
- [ ] Typo
- [ ] Bug
- [ ] Additional article idea
Hi Guys,
Busy learning SPFX and trying to build a global menu. I have it working fine on modern pages.
Expected or Desired Behavior
Load JQuery and be able to use it.
Observed Behavior
Jquery loads fine and runs with the page extension on modern pages, but doesn't work on modern lists and libraries. When viewing on a modern document library, this error comes up.
listview-host-assembly_en-us_771976365ce5d18e7f4aed77489e8f9d.js:194 Uncaught (in promise) Error: ***Failed to load path dependency "jquery" from component "6965fcda-fbc7-4e4c-bd09-17f10f75a95a" (HelloWorldApplicationCustomizer). Original error: Unknown error when loading module "6965fcda-fbc7-4e4c-bd09-17f10f75a95a_0.0.1/jquery" at t [as constructor] (listview-host-assembly_en-us_771976365ce5d18e7f4aed77489e8f9d.js:194) at new t (listview-host-assembly_en-us_771976365ce5d18e7f4aed77489e8f9d.js:281) at Function.e.buildErrorWithVerboseLog (listview-host-assembly_en-us_771976365ce5d18e7f4aed77489e8f9d.js:281) at Function.e.buildLoadPathDependencyError (listview-host-assembly_en-us_771976365ce5d18e7f4aed77489e8f9d.js:281) at listview-host-assembly_en-us_771976365ce5d18e7f4aed77489e8f9d.js:281 at listview-host-assembly_en-us_771976365ce5d18e7f4aed77489e8f9d.js:281
Steps to Reproduce
I created a new application extension for SharePoint Online. Added in JQuery as per what i have found in the docs.
Followed this doc, created a simple helloworld extension https://docs.microsoft.com/en-us/sharepoint/dev/spfx/extensions/get-started/build-a-hello-world-extension
Then installed jquery using
npm install @types/[email protected] --save-dev
Modified code to include jquery and call docready
@override
public onInit(): Promise<void> {
$(document).ready(() => {
Dialog.alert("JQuery working");
});
return Promise.resolve();
}
config.json
"externals": {
"jquery": "https://code.jquery.com/jquery-2.2.4.min.js",
"globalName":"jQuery"
}
As soon as I start to try use $ it throws the error. If I comment out doc.ready, there are no errors.
Sorry, answering my own question.
I used local jquery instead and jquery works. Sigh.
Ran the following on my project
npm install –save jquery
Then update config.json externals to look at local modules
"externals": {
"jquery":{
"path":"node_modules/jquery/dist/jquery.min.js",
"globalName":"jQuery"
}
},
et, voila, works!!!!
thx @warren-genpoint for coming back. Based on your follow up, will close the issue.
But this is still an issue, isn´t it @VesaJuvonen ? I also observed same behavior with jQuery loaded from CDN (externals) and List customiser, and I guess we should be able to use it, loaded as external CDN.
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues