jQuery is not defined in SPFx extension

%3CLINGO-SUB%20id%3D%22lingo-sub-2034506%22%20slang%3D%22en-US%22%3EjQuery%20is%20not%20defined%20in%20SPFx%20extension%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2034506%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20created%20SPFx%20extension%20(not%20a%20webpart%2C%20in%20case%20it%20makes%20any%20difference)%20and%20trying%20to%20add%20jQuery%20but%20its%20not%20doing%20it.%20I%20have%20installed%20it%20into%20package%20with%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Enpm%20install%20--save%20%40types%2Fjquery%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Eadded%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%22externals%22%3A%20%7B%0A%22jquery%22%3A%20%22.%2Fsrc%2Fextensions%2Ftracker2%2Fjs%2FJQuery_3.5.1.js%22%0A%7D%2C%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%3CBR%20%2F%3Einto%20config.json%20%2C%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Eimport%20*%20as%20jQuery%20from%20'jquery'%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Einto%20MyPackage.ts%3CBR%20%2F%3EBut%20still%20getting%20%22%20jQuery%20is%20not%20defined%20%22%20when%20trying%20to%20use%20jQuery%20in%20my%20code.%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2034506%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

I have created SPFx extension (not a webpart, in case it makes any difference) and trying to add jQuery but its not doing it. I have installed it into package with

npm install --save @types/jquery

added

"externals": {
"jquery": "./src/extensions/tracker2/js/JQuery_3.5.1.js"
},


into config.json ,

import * as jQuery from 'jquery';

into MyPackage.ts
But still getting " jQuery is not defined " when trying to use jQuery in my code.

Thanks

1 Reply

Hi @RomanRomych.

Did you ever work out what was going wrong with this?

 

I have exactly the same issue and have burned hours trying to find a solution, all without any success.