我正在尝试在 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'
我在一个干净的项目中尝试过它并且工作正常,所以我认为这个问题可能与某些 Angular 特定的配置有关。
关于可能出错的任何线索?
最佳答案
你配置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);
});
关于angular - 在 Angular 中使用 SystemJs 导入时找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62706972/