tsify
tsify copied to clipboard
Require function give wrong object
In version 0.15.4 and higher our project has problem (in 0.15.3 it works). We use grunt-browserify with aliases. Example of config for grunt:
app: {
files: {'bundle.js': ['app/main.ts']},
options: {
alias: ["./app/js/common/util.ts:docsUtil"]
configure: function tsify(b) {
b.plugin('tsify');
}
}
}
Bundle creation finish normally, but when it runs in browser there are error. Error happens because require('docsUtil') return an empty object (docsUtil is alias to real module).
Check what is in compilled output. Seems this module will be empty in bundle.
The grunt-browserify
alias
option cannot be supported by tsify
as it is currently implemented. Said option tweaks the way Browserify resolves modules. However, the TypeScript compilation would need to resolve modules the same way and, at the moment, that's not possible.
This might be something that could be addressed with the module resolution enhancements in TypeScript 2, but I have not yet looked into it, as there is a bug in the TypeScript 2.0.0 beta causes problems for tsify
and I'm waiting for the release - which should include a fix.