2

I'm use React. After create-react-app --typescript I've added few libraries to package.json after that I received exception in runtime.

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;

I tried 1) remove node_moduls/install again 2) clear cache

Fortunatly my project builds, but exception appear in runtime My 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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Egor Pashko
  • 354
  • 2
  • 8

3 Answers3

2

Try updating @types/webpack-env to latest version. Worked for me.

Jim Doyle
  • 2,302
  • 1
  • 16
  • 12
1

This usually means that the version of @types/node you've specify in your package.json's devDependencies is incompatible with the one used under the hood by one of your dependencies.

For instance you will get this error if you've specified "@types/node": "13.9.1" but use a "@nestjs/cli": "^7.0.0" because that latter lib is using itself "@types/node": "12.12.31".

A workaround for this is to lower your the @types/node version of your project to the lowest common denominator, so "12.12.31" in this example.

Jérôme Beau
  • 10,608
  • 5
  • 48
  • 52
0

After moved all @types to devDependencies exception doesn't appear

Egor Pashko
  • 354
  • 2
  • 8