使用 Umi4 搭建项目,选择antd-pro模版
+ pnpm
,运行起来以后VScode编译器中出现报红,但是项目正常运行,现在强迫症处理各种报红
如果有用请点个赞 o( ̄▽ ̄)d
1、Cannot find module ‘umi’ or its corresponding type declarations.
所有的.tsx
文件中从umi引入方法都会报Cannot find module 'umi' or its corresponding type declarations.
因为使用了antd-pro模版所以使用的不再是umi
依赖 而是使用@umijs/max
解决方案:
把对应的引入改为import { XXXXX} from '@umijs/max';
2、Property ‘div’ does not exist on type ‘JSX.IntrinsicElements’.
这个错误通常是由于在 TypeScript 中对 JSX 元素类型未定义导致的。
解决方案:
-
在 tsconfig.json
文件中增加 "jsx": "react"
(或者 "jsx": "preserve"
)选项。
{
"extends": "./src/.umi/tsconfig.json",
"compilerOptions": {
"jsx": "react"
}
}
-
在使用dom节点的文件头部引入React import React from 'react';
3、Option ‘–resolveJsonModule’ cannot be specified without ‘node’ module resolution strategy.
tsconfig.json 报错
这个错误提示意味着无法在 TypeScript 中使用 --resolveJsonModule
选项,除非您将模块解析策略设置为 node
。
解决方案:
-
在 tsconfig.json
文件中添加 "moduleResolution": "node"
选项。
{
"extends": "./src/.umi/tsconfig.json",
"compilerOptions": {
"moduleResolution": "node"
}
}