我正在使用 React。 在 create-react-app --typescript 之后,我在 package.json 中添加了一些库,然后在运行时收到异常。
TypeScript error in D:/catalog/node_modules/@types/node/globals.d.ts(223,11):
Interface 'NodeModule' cannot simultaneously extend types 'Module' and 'Module'.
Named property 'hot' of types 'Module' and 'Module' are not identical. TS2320
221 | declare var require: NodeRequire;
222 |
> 223 | interface NodeModule {
| ^
224 | exports: any;
225 | require: NodeRequireFunction;
226 | id: string;
我试过了 1)删除node_moduls/再次安装 2)清除缓存
幸运的是我的项目构建了,但运行时出现异常 我的package.json
{
"dependencies": {
"@types/bootstrap": "^4.2.0",
"@types/faker": "^4.1.4",
"@types/node": "12.11.2",
"@types/parcel-env": "^0.0.0",
"@types/ramda": "^0.25.48",
"@types/react-dom": "16.9.2",
"@types/react-router": "^4.4.3",
"@types/react-router-dom": "^4.3.1",
"@types/recompose": "^0.30.3",
"@types/styled-components": "4.1.16",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-scripts": "3.2.0",
"remotedev": "^0.2.9",
"yarn-deduplicate": "^1.1.1"
},
"devDependencies": {
"@types/react": "16.8.19",
"@types/enzyme": "^3.9.0",
"@types/enzyme-adapter-react-16": "^1.0.5",
"@types/jest": "^23.3.10",
"@types/webpack": "^4.4.24",
"@types/webpack-env": "^1.13.6",
"awesome-typescript-loader": "^5.2.1",
"cross-env": "^5.2.0",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.12.1",
"lerna": "^3.15.0",
"prettier": "^1.15.3",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0",
"tslint-eslint-rules": "^5.4.0",
"tslint-loader": "^3.5.4",
"tslint-plugin-prettier": "^2.0.1",
"tslint-react": "^3.6.0",
"typescript": "3.6.4",
"typescript-plugin-styled-components": "^1.0.0"
},
"resolutions": {
"@types/react": "16.8.19"
},
}
react / typescript / yarn 。
最佳答案
尝试将@types/webpack-env
更新到最新版本。为我工作。
关于reactjs - 接口(interface) 'NodeModule' 无法同时扩展类型 'Module' 和 'Module',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58519610/