2

我正在尝试使用 Angular 中的 SystemJs 导入外部模块

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

...

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

我也试过 http://localhost:4200/assets/example/example.js

js 文件在那里并且可以访问。

但我收到一个错误:

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

我在一个干净的项目中尝试过它,它工作正常,所以我认为问题可能与某些特定角度的配置有关。

关于什么可能是错的任何线索?

4

1 回答 1

0

你配置过 SystemJS 吗?

像这样:

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);
});
于 2020-07-08T13:19:15.100 回答