nestjs 中的 @orbitdb/core + ipfs-core

@orbitdb/core + ipfs-core in nestjs

提问人:Ismail Hosen 提问时间:11/18/2023 最后编辑:Ismail Hosen 更新时间:11/18/2023 访问量:13

问:

@orbitdb/core错误显示

`const core_1 = require("@orbitdb/core");
               ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/bs1040/Projects/orbitdb_esm_test/node_modules/@orbitdb/core/src/index.js from /home/bs1040/Projects/orbitdb_esm_test/dist/modules/db.service.js not supported.
Instead change the require of index.js in /home/bs1040/Projects/orbitdb_esm_test/dist/modules/db.service.js to a dynamic import() which is available in all CommonJS modules.`

还显示此错误(ipfs-core)

Error: No "exports" main defined in /home/bs1040/Projects/orbitdb_esm_test/node_modules/ipfs-core/package.json

我的db.service.ts文件的代码

`

  import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
  import { createOrbitDB } from '@orbitdb/core';
  import IPFS from 'ipfs-core';

  @Injectable()
  export class DBService implements OnModuleInit, OnModuleDestroy {
  private ipfs: any;
  private orbitdb: any;

  async onModuleInit() {
  this.ipfs = await IPFS.create();
  this.orbitdb = await createOrbitDB({ ipfs: this.ipfs });

  const db = await this.orbitdb.open('hello');

  db.events.on('update', async (entry) => {
      console.log(entry);
      const all = await db.all();
      console.log(all);
    });
  }

  async onModuleDestroy() {
     await this.orbitdb.stop();
      await this.ipfs.stop();
     }
  }`

依赖 “@nestjs/通用”: “^10.0.0”, “@nestjs/核心”: “^10.0.0”, “@nestjs/平台快递”: “^10.0.0”, “@orbitdb/核心”: “^1.0.0”, “ipfs核心”: “^0.18.1”, “反映元数据”:“^0.1.13”, “rxjs”: “^7.8.1”

node.js typescript npm nestjs orbitdb

评论


答: 暂无答案