Railgun-Community / waku-broadcaster-client

MIT License
1 stars 3 forks source link

Cannot start in Nest.js project #7

Open AnanTdf opened 1 year ago

AnanTdf commented 1 year ago

Reproduction steps:

  1. Create a new project by nest.js: nest new demo
  2. cd into demo project and add deps: yarn add @railgun-community/waku-relayer-client
  3. import RailgunWakuRelayerClient in app.service.ts
  4. run with yarn run start

Demo code:

import { Injectable } from '@nestjs/common';
import { RailgunWakuRelayerClient } from '@railgun-community/waku-relayer-client';
import {
  Chain,
  NETWORK_CONFIG,
  NetworkName,
  RelayerConnectionStatus,
} from '@railgun-community/shared-models';

@Injectable()
export class AppService {

  constructor() {
    const statusCallback = (chain: Chain, status: RelayerConnectionStatus) => {

    };
    const { chain } = NETWORK_CONFIG[NetworkName.BNBChain];
    RailgunWakuRelayerClient.start(chain, {}, statusCallback)

  }
  getHello(): string {
    return 'Hello World!';
  }
}

but got this error:

/demo/dist/app.service.js:14
const waku_relayer_client_1 = require("@railgun-community/waku-relayer-client");
                              ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /demo/node_modules/@railgun-community/waku-relayer-client/dist/index.js from /demo/dist/app.service.js not supported.
Instead change the require of index.js in /demo/dist/app.service.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/demo/dist/app.service.js:14:31)
    at Object.<anonymous> (/demo/dist/app.controller.js:14:23)
    at Object.<anonymous> (/demo/dist/app.module.js:11:26)
    at Object.<anonymous> (/demo/dist/main.js:4:22)
error Command failed with exit code 1.
weboko commented 1 year ago

It seems that is built only in as ES Module and thus not able to be required in the way that nest.js is doing this.