Reputation: 7386
I am trying to port a javascript app to typescript that uses requirejs. I am using the typedefinition from @mhegazy at DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped/tree/master/crossroads Typescript compiler is giving me the following error...
error TS2307: Cannot find external module 'crossroads'.
This did all work in javascript using "defines" instead.
I just used this library as a complete example. What am I missing? Documentation is hard to dig up if TSC is really even paying attention to a requirejs config. I know crossroads depends on js-signals. Is there a problem with definitions and ts files being in different directories? From what I have read here I should not have to even put the reference comment. But if I then try to use a relative path, it cannot find it either.
Here is my app structure
Application ts/js
Typescript definitions
Javascript libraries
index.html has this script include
<script data-main="app/config" src="bower_components/requirejs/require.js>
</script>
/app/config.ts:
/// <reference path="../typings/requirejs/require.d.ts" />
(function () {
requirejs.config({
baseUrl: ".",
paths: {
"crossroads": "bower_components/crossroads/dist/crossroads"
}
})
require(["app/bootup"]);
}) ();
/app/someclass.ts:
/// <reference path="../typings/crossroads/crossroads.d.ts" />
import crossroads = require("crossroads");
class SomeClass{
// do something with crossroads
}
Upvotes: 1
Views: 689
Reputation: 276057
import crossroads = require("crossroads");
To use import/require
you either need:
In your case you need to declare an external module for TypeScript to know about it. E.g.:
declare module 'crossroads'{
export = crossroads;
}
UPDATE I've updated the definitions so you don't need to do this : https://github.com/borisyankov/DefinitelyTyped/pull/3866 Enjoy!
Upvotes: 1