【问题标题】:Unable to Dynamically Load Modules in Angular 5 and Hyperledger Composer无法在 Angular 5 和 Hyperledger Composer 中动态加载模块
【发布时间】:2018-10-14 08:03:35
【问题描述】:

我构建了一个 Angular 5 应用程序,目标是从卡片存档中加载 BusinessNetworkDefinition。我似乎无法弄清楚如何在我的 Angular 应用程序中动态加载模块。当我加载卡片存档文件,然后尝试通过以下代码连接到正在运行的业务网络时,我收到错误消息。

  private fileAccepted(file: File): void {
    let fileReader = new FileReader();

    fileReader.readAsArrayBuffer(file);

    fileReader.onloadend = () => {
      this.cardService.importCard(fileReader.result).then((card) => {
        this.card = card;
        const connProfile = this.card.getConnectionProfile();
        this.connectionProfileManager.connectWithData(this.card.getConnectionProfile(), this.card.getBusinessNetworkName())
          .then((connection) => {
            console.log(connection);
          })
          .catch((err) => {
            console.log(err);
          });
      });
    }

这是抛出的错误:

Error: Failed to load connector module "composer-connector-hlfv1" for connection type "hlfv1". curmod.require is not a function-connectionManagerLoader.require is not a function-Cannot find module "."
    at Promise.resolve.then (connectionprofilemanager.js:144)
    at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)
    at Object.onInvoke (core.js:4760)
    at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387)
    at Zone.webpackJsonp../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138)
    at zone.js:872
    at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4751)
    at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at Zone.webpackJsonp../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)

为了给这种情况添加更多上下文,我在使用 webpack 编译时还收到以下错误:

WARNING in ./node_modules/composer-common/lib/connectionprofilemanager.js
132:57-69 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/composer-common/lib/connectionprofilemanager.js
 @ ./node_modules/composer-common/index.js
 @ ./src/app/services/identity-card.service.ts
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://localhost:4200 ./src/main.ts

我怀疑这与动态加载的模块有关,但我已经查看并尝试了以下问题/帖子中包含的所有解决方案:

我希望有人能从技术上解释这里发生了什么以及我应该在哪里寻找解决方案。谢谢!

【问题讨论】:

    标签: angular hyperledger-composer


    【解决方案1】:

    我对 Angular 不是很熟悉,但这是否与您在 Angular 中的 module.exports 相关 - 可能在您的 ./app/routes 模块中?您是否定义了路线 - 一些可能有帮助的资源 -> NodeJs : TypeError: require(...) is not a function 和类似问题的快速讨论 here

    最后一件事是检查 composer npm 模块是否已在您的项目中使用 npm install 安装,并且您的 package.json 具有正确的依赖项。

    【讨论】:

      猜你喜欢
      • 2018-10-13
      • 2021-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      相关资源
      最近更新 更多