使用npm安装https://github.com/halt-hammerzeit/libphonenumber-js并更新我的systemjs.config.ts以包含
map:{
...
'libphonenumber-js': 'node_modules/libphonenumber-js'
},
packages: {
...
'libphonenumber-js': {
main: './custom.es6.js',
defaultExtension: 'js'
}
},
并尝试使用
import { parse, format, asYouType } from 'libphonenumber-js';
在我的@Directive中,我坚持
找不到模块'libphonenumber-js'
我该如何将这个库连接到我的应用程序中?
编辑:
目录布局:
websiteName
websiteName / index.html的
websiteName / node_modules
websiteName / node_modules / libphonenumber-JS
websiteName /应用
websiteName / app / systemjs.config.ts
Index.html包含:
<script src="/app/systemjs.config.js"></script>
<script>
System.import('app').catch(function (err) { console.error(err); });
</script>
systemjs.config.ts包含:
declare var System: any;
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// other references
'libphonenumber-js': 'npm:libphonenumber-js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
// other references
'libphonenumber-js': {
main: './bundle/libphonenumber-js.min.js',
defaultExtension: 'js'
}
}
});
})(this);
答案 0 :(得分:1)
您的包配置不正确。它需要指向libphonenumber-js
的源文件。需要更新引用以匹配您的项目结构。
试试这个:
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': './node_modules'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// other references
'libphonenumber-js': 'npm:libphonenumber-js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
// other references
'libphonenumber-js': {
main: 'libphonenumber-js.min',
defaultExtension: 'js'
}
}
});
})(this);