1

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"
]
Rory McCrossan
  • 319,460
  • 37
  • 290
  • 318
medmoufahim
  • 82
  • 2
  • 10

1 Answers1

3

Try to install jquery.

npm install jquery

And then import jquery as $. like below

import * as $ from 'jquery';
Rise
  • 1,282
  • 7
  • 14
  • did $ have a modal method ? I'd like to show a modal: https://getbootstrap.com/docs/4.0/components/modal/#via-javascript – medmoufahim Feb 14 '20 at 14:42