0

To import the jquery library in my typescript project, I did the following.

  • npm install typings --global
  • typings install dt~jquery --global --save

Then in my typescript file, I did:

import {jquery as $} from 'jquery';

But the transcript compiler throws an error saying:

error TS2307: Cannot find module 'jquery'.

enter image description here

What is that I am missing here? Why can the compiler not find the jquery module?

Typescript version I am using : 2.1.5

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328

1 Answers1

2

You still need to make the typescript compiler aware of your typings.

Any one of these should handle your issue. Don't do more than one or they may conflict.

  • Add "typings/index.d.ts" to your tsconfig.json's files array
  • Use ///<reference path... to pull in the jquery.d.ts file.
  • Throw all of this away and use @types
Paarth
  • 9,687
  • 4
  • 27
  • 36
  • What is the difference between `typings` and `@types`? – Suhail Gupta Feb 09 '17 at 18:13
  • They're very similar, they both pull from the same source ([DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped)). Typings is a separate typings manager and you have to configure your typescript project to use its definitions. @types is integrated with npm and typescript 2.0+ and installing the @types/ npm module will be all you'll need to do for type info. – Paarth Feb 09 '17 at 18:37