问题描述
我正在按照 https://angular.io/guide/creating-libraries 上的指南创建一个库。我使用此配置构建它:
{
"extends": "../../tsconfig.base.json","compilerOptions": {
"outDir": "../../out-tsc/lib","target": "es5","declaration": true,"inlineSources": true,"types": [],"lib": [
"dom","es2018"
]
},"angularCompilerOptions": {
"skipTemplateCodegen": true,"strictMetadataEmit": true,"enableResourceInlining": true
},"exclude": [
"src/test.ts","**/*.spec.ts"
]
}
我从开箱即用的内容中唯一改变的是,我将目标从 es2015 更改为 es5。 将其发布到 npm 并将其安装到我的应用程序中后,我尝试使用 ng serve --configuration es5 运行我的应用程序(Angular 8)。
es5 配置说:
"configurations": {
"es5": {
"tsConfig": "./tsconfig.es5.json"
}
}
tsconfig.es5.json:
{
"extends": "./tsconfig.json","compilerOptions": {
"target": "ES5",}
}
tsconfig.json:
{
"compileOnSave": false,"compilerOptions": {
"baseUrl": "./src","outDir": "./dist/out-tsc","sourceMap": true,"declaration": false,"module": "ESNext","moduleResolution": "node","emitDecoratorMetadata": true,"experimentalDecorators": true,"importHelpers": true,"target": "ES2015","typeRoots": [
"node_modules/@types"
],"lib": [
"ES2018","DOM"
],"paths": {
"@config/*": ["app/config/*"],"@core/*": ["app/core/*"],"@environments/*": ["environments/*"],"@modules/*": ["app/modules/*"],"@requests/*": ["app/core/request-interfaces/*"],"@responses/*": ["app/core/response-interfaces/*"],"@shared/*": ["app/shared/*"]
}
},"angularCompilerOptions": {
"enableIvy": false
}
}
按照描述运行我的应用程序时,我从导入的库中收到此错误: 未捕获的类型错误:类构造函数 MyClass 不能在没有 'new' 的情况下被调用
它是由我从包中扩展一个类触发的: 导出类 MyClass 扩展了 PackageClass {}
我知道这个错误是由 es2015 不支持 class 关键字触发的,但是使用 es5 目标构建库不应该阻止我的应用程序像这样使用它吗?我在库文档中找不到任何关于支持 es5 浏览器的内容。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)