gpt4 book ai didi

typescript - vue-cli 构建失败并出现编译错误

转载 作者:行者123 更新时间:2023-12-01 22:52:23 25 4
gpt4 key购买 nike

我的 Vue 2.2.3 应用程序无法构建,有 4 个与 TypeScript 相关的错误,我不确定如何补救。

这是控制台的样子:

Failed to compile with 4 errors                                                          6:08:46 PM

error in node_modules/vue/types/jsx.d.ts:39:7

TS1110: Type expected.
37 | * https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors
38 | */
> 39 | [v: `--${string}`]: string | number | undefined
| ^^^^^
40 | }
41 |
42 | type Booleanish = boolean | 'true' | 'false'

error in node_modules/vue/types/jsx.d.ts:39:20

TS1005: ';' expected.
37 | * https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors
38 | */
> 39 | [v: `--${string}`]: string | number | undefined
| ^
40 | }
41 |
42 | type Booleanish = boolean | 'true' | 'false'

error in node_modules/vue/types/jsx.d.ts:39:21

TS1128: Declaration or statement expected.
37 | * https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors
38 | */
> 39 | [v: `--${string}`]: string | number | undefined
| ^
40 | }
41 |
42 | type Booleanish = boolean | 'true' | 'false'

error in node_modules/vue/types/jsx.d.ts:40:1

TS1128: Declaration or statement expected.
38 | */
39 | [v: `--${string}`]: string | number | undefined
> 40 | }
| ^
41 |
42 | type Booleanish = boolean | 'true' | 'false'
43 | type Numberish = number | string

ERROR Error: Build failed with errors.

我关注了the link在我得到以下代码的控制台输出中。我将该文件添加到我的项目 src 目录中。

// My css.d.ts file
import type * as CSS from 'csstype';

declare module 'csstype' {
interface Properties {
// Add a missing property
WebkitRocketLauncher?: string;

// Add a CSS Custom Property
'--theme-color'?: 'black' | 'white';

// ...or allow any other property
[index: string]: any;
}
}

当然上面的文件没有解决问题,我得到了同样的 TypeScript 错误。我尝试删除 '--theme-color'?: 'black' | 'white'; 但它也不起作用。

坦率地说,我不确定如何解决这些问题并让构建通过。奇怪的是,该应用程序在我的生产服务器上构建时没有任何问题。

我想补充一点,我也在使用 Veutify,它可能会或可能不会导致其中一些错误。

非常感谢任何帮助。

最佳答案

我今天在 Vue: 2.6.11 中看到了同样的错误。不确定如何处理它。

更新

我能够通过更新我的 package.json 中的 TypeScript 来解决这个问题。我认为不支持字符串文字。

我更新到 TS 版本 4.4.4

关于typescript - vue-cli 构建失败并出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74048640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com