SPFx Webpart-node_modules/@ types/[属性类型]和[反应]索引.在大吃一惊的建立 [英] SPFx Webpart - node_modules/@types/ [prop types] and [react] index.d.ts: loads of "error TS1005" on gulp build

查看:305
本文介绍了SPFx Webpart-node_modules/@ types/[属性类型]和[反应]索引.在大吃一惊的建立的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在构建一个spfx Webpart,其一个功能是显示链接预览. 我将此库用于该任务.我必须更改软件包"styled-components"的版本,并更新我的"react"(16.4.18)和"react-dom"(16.0.9)才能正常工作.进行了这些更改并运行gulp build之后,我收到以下错误列表:

So Im building a spfx webpart of which one feature is to display link previews. I used this library for the task. I had to change the version of the package "styled-components" and update my "react"(16.4.18) and "react-dom"(16.0.9) in order for it to work. After making these changes and running gulp build I receive the follwing List of errors:

[10:21:13] [tsc] typescript version: 2.4.2
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(27,38): error TS1005: '=' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(29,46): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(29,75): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(29,99): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(31,54): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(31,78): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(31,81): error TS1109: Expression expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(31,97): error TS1109: Expression expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(31,122): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(31,130): error TS1128: Declaration or statement expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(31,138): error TS1005: ',' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(44,48): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(44,49): error TS1109: Expression expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(44,50): error TS1109: Expression expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(44,68): error TS1005: '(' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(44,69): error TS1005: ')' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(46,30): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(46,54): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/prop-types/index.d.ts(46,57): error TS1109: Expression expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2297,27): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2298,14): error TS1005: ':' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2298,28): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2299,9): error TS1109: Expression expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2300,9): error TS1005: '(' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2301,9): error TS1005: '(' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2302,5): error TS1005: '(' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2302,12): error TS1005: ')' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2314,49): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2314,76): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2314,99): error TS1005: ';' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2315,13): error TS1128: Declaration or statement expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2316,13): error TS1005: '(' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2316,17): error TS1005: ',' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2316,44): error TS1005: ',' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2316,45): error TS1005: ':' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2318,17): error TS1005: '(' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2318,21): error TS1005: ',' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2318,51): error TS1005: ',' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2318,52): error TS1005: ':' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2320,21): error TS1005: '(' expected.
[10:21:17] Error - [tsc] node_modules/@types/react/index.d.ts(2320,24): error TS1005: ')' expected.
[10:21:17] Error - 'tsc' sub task errored after 3.75 s
 exited with code 2

此github问题与我的某种类似,表明我更新了我的打字稿版本到2.3.4或更高版本.

this github issue is somehow similar to mine, suggesting that I update my typescript version to 2.3.4 or above.

还有一个我现在找不到的github问题,建议将打字稿版本更新为2.8.x或更高版本.

There was another github issue which I cannot find at this time suggesting to update typescript version to 2.8.x or above.

我的打字稿版本是3.1.3.我在本地(在项目的节点模块文件夹中)和全局安装了相同版本.您可能已经注意到,在构建开始时,我告诉输出

My typescript version is 3.1.3. I have the same version installed locally (in the project's node modules folder) and globally. As you may have noticed, on build start I stell get the output

[tsc] typescript version: 2.4.2

我已将"package.json"文件以及yarn.lock文件(我正在使用yarn)中与打字稿相关的所有条目更改为"3.1.3"或〜3.1.3"表示"2.4.1"或"2.4.2"或〜2.4.1"或〜2.4.2".从我阅读的内容来看,它与定义/替代语法有关,仅在打字稿2.8及更高版本中受支持.对于等距而言,有争议的行之一是:

I have changed all entries related to typescript in the "package.json" file as well as the yarn.lock file (I am using yarn) to either "3.1.3" or "~3.1.3" as they originally said "2.4.1" or "2.4.2" or "~2.4.1" or "~2.4.2". From what I've read it is something related to definition/delcaration syntax that is only supported in typescript 2.8 and above. For istance, one of the lines in question is:

 Error - [tsc] node_modules/@types/prop-types/index.d.ts(27,38): error TS1005: '=' expected.

export const nominalTypeHack: unique symbol;

我通常对打字稿和节点还很陌生,所以这可能是导致不知道如何解决此问题的另一点.

I am pretty new to typescript and node in general, so this may be another point contributing to not knowing how to fix this.

如果要提供更多信息,我将很乐意提供.预先感谢您的所有建议和答案.

If theres more information to be provided, I will be happy to do so. Thanks in advance for all suggestions and answers.

推荐答案

我快速完成了 1 2 )表示SPFx构建系统会将人们固定在旧版本的TypeScript上.我没有找到解决方法.

I did a quick web search and found several threads (e.g., 1, 2) indicating that the SPFx build system was pinning people to an old version of TypeScript. I didn't see a solution.

一种可能的方法是将您的代码分成与React交互的一部分和与SPFx交互的一部分,使用最新版本的tsc自己将第一部分编译为JavaScript,并在生成时包含生成的JavaScript文件.通过SPFx构建系统编译第二部分.我对SPFx生成系统一无所知,无法确定是否可行.如果您尝试过并遇到特定问题,我可能会为您提供帮助.

One conceivable approach would be to separate your code into one part that interacts with React and one part that interacts with SPFx, compile the first part to JavaScript yourself using a recent version of tsc, and include the resulting JavaScript files when compiling the second part via the SPFx build system. I don't know anything about the SPFx build system to know if this might work; if you try it and run into a specific problem, I may be able to help.

另一个想法是使用与TypeScript版本兼容的@types软件包的旧版本,尽管它们可能缺少您需要的功能.例如,对于TypeScript 2.4.2,您可以通过运行npm install @types/prop-types@ts2.4(或npm install -D @types/prop-types@ts2.4;安装@types/prop-typests2.4标记;请参见

Another idea would be to use older versions of @types packages that are compatible with your TypeScript version, though they may be missing features you need. For example, for TypeScript 2.4.2, you would install the ts2.4 tag of @types/prop-types by running npm install @types/prop-types@ts2.4 (or npm install -D @types/prop-types@ts2.4; see here for details of the difference).

这篇关于SPFx Webpart-node_modules/@ types/[属性类型]和[反应]索引.在大吃一惊的建立的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆