gpt4 book ai didi

javascript - Angular 库导入 *

转载 作者:行者123 更新时间:2023-12-02 22:24:49 24 4
gpt4 key购买 nike

所以我在库中使用的模块之一是 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

最佳答案

试试这个..

npm install --save @types/sha256

然后

import sha256 from 'sha256';

or

import * as sha256_ from 'sha256';

关于javascript - Angular 库导入 *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59104685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com