One of the key modules in my library is sha256
. To import it, I had to use the following syntax:
import sha256 from 'sha256';
However, while researching this issue, I came across a question on Stack Overflow titled: Errors when using MomentJS in Angular Typescript library
The suggestion was that I needed to handle the import differently during compilation:
I initially changed my import statement to:
import * as sha256_ from 'sha256';
const sha256 = sha256_;
Unfortunately, this also resulted in the same error message:
ERROR: Cannot call a namespace ('sha256')
An unhandled exception occurred: Cannot call a namespace ('sha256')
Next, I attempted to modify my tsconfig.json
:
"angularCompilerOptions": {
"allowSyntheticDefaultImports": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
Despite making these adjustments, I still encountered issues.
Could someone guide me on how to correctly manage this particular import in my library?
Edit
In addition, I included it in the compilerOptions
:
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"inlineSources": true,
"allowSyntheticDefaultImports": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
ng --version
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