简体   繁体   English

SPFx 不能使用 JQuery?

[英]SPFx can't use JQuery?

I'm working on a brand new SharePoint Web Part using SPFx created by Yeoman, the scaffolding template is fine, adding the NPMs for JQuery and JQueryUI also get not a single problem, I see GULP SERVE running in the background without any errors.我正在使用 Yeoman 创建的 SPFx 开发一个全新的 SharePoint Web 部件,脚手架模板很好,为 JQuery 和 JQueryUI 添加 NPM 也没有遇到任何问题,我看到GULP SERVE在后台运行,没有任何错误。

The problem happens when I add the following line inside my JQWebPart.ts:当我在 JQWebPart.ts 中添加以下行时会出现问题:

      import * as jQuery from 'jquery';

Once the line above is added the GULP SERVE outputs a very long list of errors, below are the last lines from all the errors:添加上面的行后, GULP SERVE会输出一长串错误,下面是所有错误的最后一行:

[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7502,33): error TS2314: Generic type 'Callbacks<T, Function>' requires 2 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7503,36): error TS2314: Generic type 'Deferred<TR, TJ, any, TN>' requires 4 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7504,41): error TS2314: Generic type 'Event<TTarget, EventTarget, TData>' requires 3 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7505,36): error TS2314: Generic type 'Deferred<TR, TJ, any, TN>' requires 4 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7506,37): error TS2314: Generic type 'AjaxSettings<TContext, any>' requires 2 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7510,28): error TS2314: Generic type 'jqXHR<TResolve, any>' requires 2 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7511,35): error TS2314: Generic type 'Promise<TR, TJ, any, TN>' requires 4 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7517,32): error TS2314: Generic type 'PlainObject<T, any>' requires 2 type argument(s).
[16:54:06] Finished subtask 'tslint' after 3.95 s
[16:54:06] Error - 'typescript' sub task errored after 3.95 s
 "TypeScript error(s) occurred."

I have no idea what is going on with my Web Part when I try to use JQuery, does any body have any ideas???当我尝试使用 JQuery 时,我不知道我的 Web 部件发生了什么,有没有人有任何想法???

Thanks to user Rohit Waghela, there is a solution already in place to solve issues related to JQuery in SPFx:感谢用户 Rohit Waghela,已经有一个解决方案可以解决与 SPFx 中的 JQuery 相关的问题:

https://thechriskent.com/tag/sharepoint-framework/ https://thechriskent.com/tag/sharepoint-framework/

The problem is incompatibility between TypeScript and JQuery, so the bottom line here is the following:问题是 TypeScript 和 JQuery 之间的不兼容,所以这里的底线如下:

1) remove JQuery: npm uninstall @types/jquery 1) 删除 JQuery: npm uninstall @types/jquery

2) install compatible version: npm install @types/jquery@2.0.48 --save-dev 2)安装兼容版本: npm install @types/jquery@2.0.48 --save-dev

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

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