How to import a typescript module
Hi team,
I'm trying to import a md5 ts module in my angular 2 project, which is https://www.npmjs.com/package/ts-md5
I've followed these instructions https://github.com/angular/angular-cli/issues/274
1 - npm install ts-md5 --save
2 - I've copied/pasted md5.js into the folder assets/js
3 - As returned in the README file of the module site, I imported the module in my component file like this:
import {Md5} from 'ts-md5/dist/md5';
When I ran my project, I got this error:
GET http://localhost:4200/ts-md5/dist/md5 404 (Not Found)
So, I added to my System config this line:
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
},
paths: {
'ts-md5/dist/md5': 'assets/js/md5.js'
}
});
OK, now, It works.
But, I still have one error (non-blocking)
md5.js:364 Uncaught ReferenceError: exports is not defined
Corresponding to this line code:
exports.Md5 = Md5;
Is there a better way to include the md5 ts module ? How to remove this error ?
Hi, copy-paste that module to src/app somewhere, then just use the right path when importing in your .ts files. Please let me know if this works for you.
Hi @guillaumeleone,
MD5 seems to have been compiled with CommonJS. You can specify SystemJS configuration to use it with something like this:
System.config({
meta: {
'assets/js/md5.js': {
format: 'commonjs'
}
}
});
Closing this. Reopen if the above doesn't solve it.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.