5

I am trying to import a node module into Angular 2 but with no avail.

How can this be achieved?

I am trying to import the following module into Angular 2: https://www.npmjs.com/package/countryjs

Do i need to use system.js to register it into the current app:

<!-- 2. Configure SystemJS -->
    <script>
      System.config({
        packages: {
          app: {
            format: 'register',
            defaultExtension: 'js'
          },
          map: {
              'countryjs': 'node_modules/countryjs/lib/countryjs'
          },
          meta: {
              // sets meta for modules within the package
              'vendor/*': {
                  'format': 'global'
              }
          }
        }
      });
      System.import('app/boot')
            .then(null, console.error.bind(console));


    </script>

Then in the ts file, I use:

import {} from "countryjs"

When i use this (below) it gives me an error

import {Country} from "countryjs"

Am I missing something?

7
  • whats the error you got ? Commented Mar 13, 2016 at 14:33
  • Uncaught SyntaxError: Unexpected token < Commented Mar 13, 2016 at 15:04
  • One question, should i browserify the library? Commented Mar 13, 2016 at 15:06
  • 1
    Will create a plunker asap Commented Mar 16, 2016 at 6:51
  • 1
    Did you solve the problem? Please post the solution. I have a similar problem. Commented Mar 19, 2016 at 11:58

1 Answer 1

3

First of all sorry for not posting for so long.

I finally found a solution for this. Please find the altered system.js script:

System.config({
                defaultJSExtensions: true,
                packages: {
                    'app': { format: 'register', "defaultExtension": 'js' }
                },
                map: {
                    'angular2': 'node_modules/angular2',
                    'primeng': 'node_modules/primeng',
                    'rxjs': 'node_modules/rxjs',
                    'ng2-uploader': 'node_modules/ng2-uploader/ng2-uploader',
                    'countryjs': 'node_modules/countryjs'
                }
            });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.