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'.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With