Saturday, August 22, 2015

Conflict between NodeJS's require and RequireJS's require TypeScript definitions

At the time of this writing, if you wanted to use TypeScript's umd (Universal Module Definition), you'll get an error between NodeJS's require and RequireJS's require TypeScript definitions.




A temporary solution to that is to disable the RequireJS's require, delete the ambient declaration for requirejs's require.

/typings/requirejs/require.d.ts
// Ambient declarations for 'require' and 'define'
declare var requirejs: Require;
// declare var require: Require // Delete or uncomment this
declare var define: RequireDefine;


This client-side config.ts won't work anymore:
requirejs.config({
    paths: {
        "jquery": "/jquery/dist/jquery"
    }
});
 
require(['app']); // this won't work


To make that work, access the client-side require via window object.
requirejs.config({
    paths: {
        "jquery": "/jquery/dist/jquery"
    }
});
 
var need : Require = window["require"];
need(['app']);

No comments:

Post a Comment