create-react-app错误导入类型*以'./types'的漂亮格式导入为PrettyFormat [英] create-react-app error import type * as PrettyFormat from './types' in pretty-format
问题描述
这是cra的全新安装,带有在节点13.11.0上运行的打字稿模板,尝试运行npm start时出现错误
it's a fresh install of cra with typescript template running on node 13.11.0 it gives me error when try to run npm start
TypeScript error in D:/Projects/personal-site/node_modules/@types/testing-library__react/node_modules/pretty-format/build/index.d.ts(7,13):
'=' expected. TS1005
5 | * LICENSE file in the root directory of this source tree.
6 | */
> 7 | import type * as PrettyFormat from './types';
| ^
8 | /**
9 | * Returns a presentation string of your `val` object
10 | * @param val any potential JavaScript object```
推荐答案
更新
感谢 marcelo-waisman 的帖子。
如果我们遵循文档紧密...
If we follow the documentation tightly...
yarn add typescript @types/node @types/react @types/react-dom @types/jest
...我们应该已经安装了具有最新版本的TypeScript,而不是可能仍低于3.8.0的本地全局版本。
... we should have installed TypeScript with the latest version, rather than the local-global version which may still below 3.8.0.
我找到了一些线索。
它与软件包 pretty-format
及其类型在<$中有关。 c $ c> create-react-app 。
我们可以在这里找到源代码: pretty-format / src / index.ts
It's related to the package pretty-format
and its type in create-react-app
.
We can find the source here: pretty-format/src/index.ts
import style = require('ansi-styles');
import type * as PrettyFormat from './types';
从提交历史记录中,我们可以看到有一个相关的拉出请求从两天前开始,该部分从...更改为...
From the commit history, we can see there is a related Pull Request from two days ago, which changed this part from...
import * as PrettyFormat from './types';
...到...
import type * as PrettyFormat from './types';
这似乎是错误的原因。
这篇关于create-react-app错误导入类型*以'./types'的漂亮格式导入为PrettyFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!