Typescript Compiler error TS2307: Cannot find module 'jquery'
Asked Answered
E

2

7

I was following JSPM getting started guide and I want to install jquery package so I execute below command.

jspm install jquery

But when I try to import it in typescript like below

import $ from 'jquery'

I'm getting a error from typescript compiler saying error TS2307: Cannot find module 'jquery'. Not only for this library for other libraries I'm getting the same error.

Erastes answered 30/1, 2016 at 13:36 Comment(0)
M
5

You need to include type definitions for jquery in the compilation context, you can grab them from https://github.com/DefinitelyTyped/DefinitelyTyped

Montana answered 30/1, 2016 at 14:51 Comment(2)
Thanks for the help. What if that module type definition file is not available there?Erastes
Then I'd check github.com/typings/typings and if that doesn't have them then you'll have to write your own type definitions. When writing type definitions you don't have to define the entire API at once, you can just define the bits you're using. And if you just want to use a lib without type definitions you can do so with declare module 'somelib' { var a: any; export = a; }.Montana
C
-1

I encountered on exactly same kind of error during VSBuild on Azure DevOps.

In my case, solution was just add new extra step Install npm into build pipeline and error was gone.

AzureDevOps Step

I hope it will help somebody!

Censurable answered 3/3, 2020 at 20:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.