0

So one of the modules that i use in my library is sha256. This has to be imported as such:

import sha256 from 'sha256';

Now I read on this SO question: Errors when using MomentJS in Angular Typescript library

That you need to do it differently when compiling:

So at first, I changed it to:

import * as sha256_ from 'sha256';
const sha256 = sha256_;

However these threw the same error:

ERROR: Cannot call a namespace ('sha256')
An unhandled exception occurred: Cannot call a namespace ('sha256')

Then i tried to edit my tsconfig.json:

  "angularCompilerOptions": {
    "allowSyntheticDefaultImports": true,
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }

However without any success.

Can anyone tell me how I can correctly build my library with such an import?

Edit

I also added it to 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
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364

1 Answers1

1

Try this..

npm install --save @types/sha256

then

import sha256 from 'sha256';

or

import * as sha256_ from 'sha256';
hbamithkumara
  • 2,344
  • 1
  • 17
  • 17