Skip to content

How to import a typescript module #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
guillaumeleone opened this issue Mar 20, 2016 · 4 comments
Closed

How to import a typescript module #327

guillaumeleone opened this issue Mar 20, 2016 · 4 comments

Comments

@guillaumeleone
Copy link

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 #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 ?

@guillaumeleone guillaumeleone changed the title How to add a typescript module How to import a typescript module Mar 20, 2016
@jkuri
Copy link
Contributor

jkuri commented Mar 20, 2016

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.

@hansl
Copy link
Contributor

hansl commented Mar 21, 2016

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'
    }
  }
});

@hansl
Copy link
Contributor

hansl commented Mar 21, 2016

Closing this. Reopen if the above doesn't solve it.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants