tsify icon indicating copy to clipboard operation
tsify copied to clipboard

Require function give wrong object

Open iKBAHT opened this issue 8 years ago • 2 comments

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).

iKBAHT avatar May 20 '16 15:05 iKBAHT

Check what is in compilled output. Seems this module will be empty in bundle.

timofei-iatsenko avatar May 23 '16 14:05 timofei-iatsenko

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.

cartant avatar Aug 28 '16 03:08 cartant