'TS2403: Subsequent variable declarations must have the same type. After NPM install

I've searched stack overflow for this issue, but am still unclear on why this is happening/how to fix.

I wanted Node Typings in my Typescript project so I entered this command:

npm install @types/node --save

Which resulted in:

c:/xyz/node_modules/@types/node/index.d.ts(89,13)
error TS2403: Subsequent variable declarations must have the same type.
Variable 'require' must be of type 'Require', but here has type 'NodeRequire'.

My machine had node version 7.0.3 The installed types was for version + @types/[email protected]

If I remove uninstall the typings my project compiles with no problems.

It appears as if the typings content is not correct per the error message! Fixing it is messy. Any tips?

Here's the failing line of code in index.d.tsNodeRequire

Seems like the NodeRequire (interfaces) need to be bypassed in favor of Require.js?

This is the TSConfig file:

{
    "compilerOptions": {
        "module": "amd",
        "moduleResolution": "node",
        "target": "es5",
        "noImplicitAny": false,
        "jsx": "react",
        "sourceMap": false,
        "baseUrl": ".",
        "paths": {
            "OfficeFabric/*": [
                "node_modules/office-ui-fabric-react/lib-amd/*"
            ]
        }
    } 
}

I tried the Exclude suggestion below which didn't work. Github says, if module resolution is NODE then exclude won't work anyway.



Solution 1:[1]

I faced this issue many times in my project at work, I solved it by uninstalling the existing node_modules and installing a newer version of the existing node_modules.

Solution 2:[2]

I have faced this issue many times in my project at work. I solved it with a change in the typings.d.ts` file:

declare var require: any;

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 Abhirajsinh Thakore
Solution 2 jps