reactjs - 接口(interface) 'NodeModule' 无法同时扩展类型 'Module' 和 'Module'

标签 reactjs typescript create-react-app yarnpkg package.json

我正在使用 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/

相关文章:

javascript - 无法将 ngModel 绑定(bind)到 p-dropdown 值(Angular)

javascript - 用于从字符串创建 JSX 元素的正确 TypeScript 类型

reactjs - Material-UI 和 React : Using the Fade component onScroll

reactjs - typescript react HOC 仅将 ref 添加到 ComponentClass

javascript - 如何使用特定版本的 create-react-app 创建一个 React 项目?

reactjs - 有没有办法迁移到CRA?

javascript - 将 Create-React-App 与 antd 结合使用

javascript - Ant树设计中如何将TreeNode做成链接?

javascript - 如何在 react 表中进行默认排序

typescript - 具有模板文字类型的属性路径