delegatexyz/delegate-javascript-sdk

SDK is not compatible with Node.js

Closed this issue · 5 comments

Steps to reproduce:

  1. Create dc.js
require('delegatecash')
  1. Run node dc.js:
$ node dc
/private/tmp/node_modules/delegatecash/index.js:37
import { ethers } from 'ethers';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1088:15)
    at Module._compile (node:internal/modules/cjs/loader:1123:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/private/tmp/dc.js:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)

Node.js v18.12.0

This issue has been resolved in 0.4.1. Thanks for bringing it to our attention @raymondfeng

Hey @ryeshrimp, the issue still persists. I get this issue when importing as commonjs module.

I am also facing same commonjs module issue.

Error [ERR_REQUIRE_ESM]: require() of ES Module <path> from <path> not supported.
Instead change the require of index.js in <path> to a dynamic import() which is available in all CommonJS modules.

@ryeshrimp is it something you are going to work on? Having same issue.

I'm also facing the same issue when my TS is compiled into javascript file it's converted from import { DelegateCash } from 'delegatecash' to const DelegateCash = require("delegatecash"); and it generates the error

const DelegateCash = require("delegatecash");
                     ^
Error [ERR_REQUIRE_ESM]: require() of ES Module