简体   繁体   English

打字稿编译器错误 TS2307:找不到模块“jquery”

[英]Typescript Compiler error TS2307: Cannot find module 'jquery'

I was following JSPM getting started guide and I want to install jquery package so I execute below command.我正在关注 JSPM 入门指南,我想安装 jquery 包,所以我执行以下命令。

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'.我收到来自打字稿编译器的error TS2307: Cannot find module 'jquery'. Not only for this library for other libraries I'm getting the same error.不仅对于其他库的这个库,我也遇到了同样的错误。

您需要在编译上下文中包含jquery类型定义,您可以从https://github.com/DefinitelyTyped/DefinitelyTyped获取它们

I encountered on exactly same kind of error during VSBuild on Azure DevOps.我在 Azure DevOps 上的 VSBuild 期间遇到了完全相同的错误。

In my case, solution was just add new extra step Install npm into build pipeline and error was gone.就我而言,解决方案只是添加新的额外步骤Install npm到构建管道中,错误消失了。

AzureDevOps 步骤

I hope it will help somebody!我希望它会帮助某人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM