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

3
  • 1
    stackoverflow.com/questions/12763684/… take a look here Commented Feb 9, 2017 at 17:22
  • @VladuIonut Could you let me know the mistake I am making? Commented Feb 9, 2017 at 17:25
  • import * as $ from "jquery"; try this syntax Commented Feb 9, 2017 at 17:31

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

What is the difference between typings and @types?
They're very similar, they both pull from the same source (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/<project> npm module will be all you'll need to do for type info.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.