【问题标题】:Cannot find module when importing with SystemJs in Angular在 Angular 中使用 SystemJs 导入时找不到模块
【发布时间】:2020-10-23 16:19:25
【问题描述】:

我正在尝试在 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'

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

有什么可能是错误的线索吗?

【问题讨论】:

  • 如果您在构建后在该文件夹中导航,此文件是否放置在您指定的路径中?
  • @Ostn,不,不是,但谢谢
  • @Sergey,是的,是的,我可以导航到资产或 uri,我可以找到它。

标签: angular system systemjs aot systemjs-builder


【解决方案1】:

你配置过 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);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-28
    • 2017-08-24
    • 2016-07-19
    • 2016-07-05
    • 2016-12-11
    • 2022-11-11
    • 2020-11-18
    相关资源
    最近更新 更多