react.js - react+typescript问题
本文介绍了react.js - react+typescript问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
按@types安装react以后运行,
出现错误
(2632,14): error TS2300: Duplicate identifier 'Element'.
我把@types/react-dom和@types/react-router里的node_modules删除后就不报错了(这两个node_modules里又重复引用了@types/react)
看上去是重复依赖的问题,请问有什么配置的方法解决吗,
ts.config如下:
{
"compilerOptions": {
"noImplicitAny": false,
"removeComments": true,
"moduleResolution": "node",
"target": "es6",
"sourceMap": true,
"jsx": "react",
"types": ["node"],
"baseUrl": "./src",
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules"
]
}
解决方案
orz..我现在webpack编译的时候也出现这个问题了
ERROR in D:\n_workspace\react_demo\node_modules\@types\react-redux\node_modules\@types\react\index.d.ts
(2632,14): error TS2300: Duplicate identifier 'Element'.
ERROR in D:\n_workspace\react_demo\node_modules\@types\react-router\node_modules\@types\react\index.d.ts
(2632,14): error TS2300: Duplicate identifier 'Element'.
ERROR in D:\n_workspace\react_demo\node_modules\@types\react-dom\node_modules\@types\react\index.d.ts
(2632,14): error TS2300: Duplicate identifier 'Element'.
ERROR in D:\n_workspace\react_demo\node_modules\@types\react\index.d.ts
(2632,14): error TS2300: Duplicate identifier 'Element'.
这篇关于react.js - react+typescript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文