Home » Jquery » angular – I can't use JQuery : Cannot find name '$'-Exceptionshub

angular – I can't use JQuery : Cannot find name '$'-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I have a problem using jQuery in my project (with Angular and boosted which is a fork of bootstrap). The error is below:

ERROR in folder/containing/my/component.ts: error TS2581: Cannot find name ‘$’. Do you need to install type definitions for jQuery? Try npm i @types/jquery.

I have installed @types/jquery and jquery, and I have added the script in angular.json file:

"dependencies": {
   // ...
  "boosted": "^4.3.1",
  "bootstrap": "^4.4.1",
},
"devDependencies": {
  // ...
  "typescript": "~3.1.6"
}

"scripts":[
  // ...
  "node_modules/@types/jquery/dist/jquery.slim.d.ts",
  "node_modules/jquery/dist/jquery.js"
]
How to&Answer:

Try to install jquery.

npm install jquery

And then import jquery as $. like below

import * as $ from 'jquery';