简体   繁体   English

在 Angular 中使用 SystemJs 导入时找不到模块

[英]Cannot find module when importing with SystemJs in Angular

I'm trying to import an external module with SystemJs in Angular doing我正在尝试使用 Angular 中的 SystemJs 导入外部模块

    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我也试过 http://localhost:4200/assets/example/example.js

The js file is there and accessible. js 文件在那里并且可以访问。

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.我在一个干净的项目中尝试过,它工作正常,所以我认为问题可能与一些 angular 特定配置有关。

Any clue about what can be wrong?关于什么可能是错的任何线索?

Have you configure SystemJS?你配置过 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);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM