3

I'm trying to import an external module with SystemJs in Angular doing

    import { System } from 'systemjs';
    declare const SystemJS: System;

...

    SystemJs.import('./assets/example/example.js').then(m=>{
      console.log('the module is', m);
    });

I also tried with http://localhost:4200/assets/example/example.js

The js file is there and accessible.

But I'm getting an error:

ERROR Error: Uncaught (in promise): Error: Cannot find module 'http://localhost:4200/assets/example/example.js'

I tried it in a clean project and it works fine, so I think the problem can be related to some angular specific configuration.

Any clue about what can be wrong?

caraie
  • 1,094
  • 7
  • 18

1 Answers1

0

Have you configure SystemJS?

Like this:

System.config({
  baseURL: './src/app',

  // Set paths your modules
  paths: {
    'example': 'assets/example/example.js'
  }
});

SystemJs.import('example').then(m=>{
  console.log('the module is', m);
});
Ale_Bianco
  • 387
  • 2
  • 9