4

I have a question about loading jquery as external in SharePoint Framework. I have worked through at least 20 different samples from at least as many different people and many of them MVP's. I can safely say that none of the samples is worth it's salt when it comes to explaining the concept to a beginner.

To load jquery as an external, what i have gathered is: specify jquery as external as follows in the config.js file

          "externals": { 
              "jquery" : "https://code.jquery.com/jquery-3.2.1.min.js"

                      }

Once this is done, in the webpart.ts file,

                     import 'jquery';
                  declare var jQuery;

This doesn't seem to work at all. I have followed at least 20 different tutorials and samples. I can get it to work, however, if i did npm install jquery. Then it all works. However, none of the tutorials I have followed tell this step so I am not including that step either.

Can someone guide me the right direction?

Thanks

  • what error you are getting? Is it error TS2307: Cannot find module 'jquery'. – ThinkB4Code Jul 10 '17 at 5:10
2

Try

import * as $ from 'jquery';

Instead of

import 'jquery';

For reference Loading a script from a CDN

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.