I am using the AutoMapper package with TypeScript version 2.0.3 but when I try to import it, I always get the error "'automapper-ts' is not a module":
If I look in the definition file, it starts with:
declare module AutoMapperJs {
and it contains export statements.
If I change my import statement to this, it compiles:
import {} from 'automapper-ts/dist/automapper';
but then I don't get a Require statement and the global automapper static variable is not found at runtime. To get it to work, I have to replace the import statement with a reference:
/// <reference path="../../node_modules/automapper-ts/dist/automapper.d.ts" />
and then add a manual JavaScript link:
<script src="lib/automapper-ts/dist/automapper.js"></script>
Can anyone explain what I am doing wrong?
Try import "automapper-ts/dist/automapper";
which should import the package and let you use the automapping stuff such as automapper.initialize(<...>);
and so on.
This is similar to the RxJS package which is also not modularized and global (as far as I remember).
Thanks. Following the above suggestion and comments below, here is what I had to change to get everything working, although I still get the compiler error during build (see note below):
Add this to the systemjs.config.js file:
map: {
'rxjs': 'npm:rxjs',
'automapper-ts': 'npm:automapper-ts',
},
packages: {
"automapper-ts": {
defaultExtension: 'js'
},
}
Then just use the import statement in my component.ts file:
import 'automapper-ts/dist/automapper';
This generated the correct Require statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With