I am using Angular, TypeScript and ES6 module syntax. Suppose I have a module defined as follows:
// SubModule.ts import MyService from 'services/MyService'; export default angular.module('subModule', []) .service('myService', MyService);
Compiled JavaScript will look like this:
var MyService_1 = require('services/MyService'); exports.default = angular.module('subModule', []) .service('myService', MyService_1.default);
My application depends on this module. Therefore, the following is in the App.ts file:
// App.ts import SubModule from 'modules/SubModule'; angular.module('app', [SubModule.name]);
With the following compiled JavaScript:
var SubModule_1 = require('modules/SubModule'); angular.module('app', [SubModule_1.default.name]);
So now I'm trying to link this for a browser. I am currently trying to use Browserify, but I am ready to use any binding tool. Browserify gives me an error, for example:
Unable to find module modules / SubModule 'from' C: \ the \ path \ to \ my \ app '
So, how do I get Browserify to work? Or is there another tool that will work better? I found this problem on Github, which seems to say that the default export from TypeScript is not compatible with CommonJS . So what should I do?
EDIT . So I think I found the problem. Browserify requires local paths to start with ./ . So, for example, I will need to reference my submodule as follows:
import SubModule from './modules/SubModule';
Does anyone know of a Browserify plugin that will automatically search for a relative path even if I don't specify ./ ? My application is quite large and I donโt want to go through and modify all import statements.
Or, on the other hand, is there a TypeScript compiler option for emit './modules/SubModule' for 'modules/SubModule' ?