所以我在图书馆使用的一个模块是
sha256
import sha256 from 'sha256';
现在我读到这个问题:
Errors when using MomentJS in Angular Typescript library
在编译时需要以不同的方式执行:
所以一开始,我把它改成:
import * as sha256_ from 'sha256';
const sha256 = sha256_;
但是,这也引发了同样的错误:
ERROR: Cannot call a namespace ('sha256')
An unhandled exception occurred: Cannot call a namespace ('sha256')
然后我试着编辑我的
tsconfig.json
:
"angularCompilerOptions": {
"allowSyntheticDefaultImports": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
但是没有成功。
有人能告诉我如何用这样的导入正确地构建我的库吗?
编辑
我还把它添加到
compilerOptions
:
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"inlineSources": true,
"allowSyntheticDefaultImports": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
ng—版本
Angular CLI: 8.3.20
Node: 10.16.0
OS: win32 x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.803.20
@angular-devkit/build-angular 0.803.20
@angular-devkit/build-ng-packagr 0.803.20
@angular-devkit/build-optimizer 0.803.20
@angular-devkit/build-webpack 0.803.20
@angular-devkit/core 8.3.20
@angular-devkit/schematics 8.3.20
@angular/cli 8.3.20
@ngtools/webpack 8.3.20
@schematics/angular 8.3.20
@schematics/update 0.803.20
ng-packagr 5.7.1
rxjs 6.4.0
typescript 3.5.3
webpack 4.39.2