Conflict between RequireJs and NodeJS definitions in Typescript

node.js, requirejs, typescript

Solution

That is true. What I had to do was simply use declare var require:any and not reference nodejs or RequireJS.

Would appreciate if you can open a bug here : https://github.com/borisyankov/DefinitelyTyped

Reason why it's tricky is because you don't actually have both node and RequireJS in the same environment. It's a compile time reuse thing we need to support.

Problem

I got the Typescript RequireJS definition from Definitely Typed - which has an ambient declaration of Require that conflicts with the NodeJs command "require". Here's the declaration and the error: Declaration: ``` declare var require: Require; ``` Error: ``` C:/.../require.d.ts(320,13): error TS2134: Subsequent variable declarations must have the same type. Variable 'require' must be of type '{ resolve(id: string): string; cache: any; extensions: any; main: any; (id: string): any; }', but here has type 'Require'. ```

Original source