Reputation: 2415
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'.
Upvotes: 6
Views: 3134
Reputation: 460
I had this issue while trying to integrate monaco-editor in my application. Workaround is pretty simple.
Insert this line
<script>window.requirejs = window.require;</script>
after included require.js
or loader.js
in your html.
Then in your .ts file where you want to use requirejs, replace all require
with requirejs
. This alias is already defined in require.d.ts
Done!
Upvotes: 1
Reputation: 12275
i was having this issue and removed this from the typings.json
"require": "registry:dt/require#2.1.20+20160316155526"
not sure how it got into my project, but i'm not using require client side.
Upvotes: -1
Reputation: 276191
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.
Upvotes: 2