'Resolve 'Conflicting definitions for node' TS4090 error in VS 2017

I have a TypeScript project that builds and runs, but I have a ton of build errors that all seem to stem from one error:

TS4090: (TS) Conflicting definitions for 'node' found at 'C:/[projectpath]/node_modules/@types/node/index.d.ts' and 'C:/[user path to Microsoft]/Typescript/3.1/node_modules/@types/node/index.d.ts'. Consider installing a specific version of this library to resolve the conflict.

I don't understand the bit about "installing a specific version of this library". I'm not certain why two versions are being found to begin with.

My app has a tsconfig.json file located in the ClientApp folder. It contains the following:

{
  "compileOnSave": false,
  "compilerOptions": {
    "module": "esnext",
    "skipLibCheck": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "target": "es2015",
    "lib": [
        "es2016",
        "es2017",
      "dom"
    ],
    "moduleResolution": "node",
    "allowJs": true,
    "baseUrl": "src"
  },
  "include": [
    "./src/**/*.ts",
    "./test/**/*.ts",
    "./custom_typings/**/*.d.ts"
  ],
    "atom": {
        "rewriteTsconfig": false
    },
    "typeAcquisition": {"enable": false}
}

I added the typeAcquisition recently based on comments on other posts relating to this -- but it had no affect.

What do I need to do to "install a specific version of this library"?

Environment

The project targets .NetCore 2.2. The project contains WebAPI Controllers that serve up backend data as well as a ClientApp folder that contains a SPA UI created with Aurelia. I use WebPack to build the SPA application.

Errors

enter image description here



Solution 1:[1]

I fixed this by moving

"@types/node": "^10.11.6"

from devDependencies to the peerDependencies in my package.json file

"peerDependencies": {
    "@types/node": "^10.11.6"
  },

Solution 2:[2]

For me, I fixed it by change/add "typeRoots" in compilerOptions (tsconfig.json)

"compilerOptions": {
        ....
         "typeRoots": [
            "node_modules/@types"
        ]
        ....
}

Solution 3:[3]

For me, it was karma.config file, which was causing the issues.

After I have deleted some of the types in the package.json, I managed to reduce the number of errors and there was only one - between signalr and karma.

Screenshot of error

For some reason I had a .js, not .ts karma config.
After I had switched to the correct configuration and restarted the VS, the problem was resolved.

It have needed some version of node as there was a require function used.
My theory is, Visual Studio automatically included types for accessible version of node, as a part of linting functionality for JavaScript.
But then, after it compiled typescript, another version of types for node was included - conflicting with the one already present.

None of the operations in tsconfig.json file would have resolved the issue, as the conflict was present between node types for TS and node types for JS.

Solution 4:[4]

In my case, the packages electron and node-opcua were using different @types/node versions, resulting in the "TS4090: (TS) Conflicting definitions for 'node" error.

I had successfully fixed that error by providing manually a version for @types/node in my peerDependencies as pointed out in the error, however after installing the project elswhere this version changed and it turned out to be a bad idea. So I added npm dedupe as a posinstall script in my package.json and it works fine.
As the documentation states, it browses through the whole dependency tree and removes duplicated packages by moving them up the tree.

Solution 5:[5]

Fixed that by

rm -rf node_modules
rm package-lock.json
npm i

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 4imble
Solution 2 Mahrez BenHamad
Solution 3 Mr Patience
Solution 4 FrelonGuepe
Solution 5 chek