Search code examples
requirejstypescriptamd

Can not locate typescript external modules in bower package


I made a bower package with typescript source(external modules). In another project, I installed my bower package using

bower install wrath

and referred that package with amd require.

import Model = require('wrath/Model');

Then tsc compiler give an error error TS2307: Cannot find external module. I can't figure out how to make the compiler know it should lookup that module in bower_components folder.

I have a folder structure like this.

app
    main.ts
bower_components
    wrath
        Model.ts
        View.ts
        ...

Does anyone have a solution to this?

I actually found a way to work around this by making a symbolic link of bower package directory along side with the app directory. Looking for a better way.


Solution

  • I can't figure out how to make the compiler know it should lookup that module in bower_components

    There is no solution other than hard references for now:

    import Model  = require('./bower_components/wrath/Model');
    

    Note: there is great desire to support node_modules : https://github.com/Microsoft/TypeScript/issues/247

    Note: grunt-ts can help you make these references : https://github.com/TypeStrong/grunt-ts#transforms