@orbitdb/core + ipfs-core in nestjs

45 Views Asked by At

@orbitdb/core error show

`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.`

also show this error (ipfs-core)

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

My db.service.ts file's code

`

  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();
     }
  }`

Dependencies "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", "@orbitdb/core": "^1.0.0", "ipfs-core": "^0.18.1", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1"

0

There are 0 best solutions below