ucan.storage icon indicating copy to clipboard operation
ucan.storage copied to clipboard

As is: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ...

Open TerasakaKazuma opened this issue 2 years ago • 4 comments

I am trying to implement in the backend Nestjs to create a UCAN token.

However, I have a problem with the


import { KeyPair } from 'ucan-storage/keypair’;

I can't get the import to work.


Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:

error occurs.

TerasakaKazuma avatar Jun 08 '22 05:06 TerasakaKazuma

can you give a snippet of your code so we can better review this error ?

hugomrdias avatar Jun 20 '22 16:06 hugomrdias

Any updates on this topic? I have the same problem with my expressJS application (using typescript)

Here is a snippet

import KeyPair from 'ucan-storage/keypair'

// KeyPair.create returns a promise, so it should be called from an async function or resolved with `.then`
async function createNewKeypair() {
  const kp = await KeyPair.KeyPair.create()

  // log the DID string for the public key to the console:
  console.log(kp.did())
}

but as you can see it has been copy-pasted from the README.md file.

stefanodecillis avatar Aug 05 '22 14:08 stefanodecillis

Any update on this? I have the same problem with a default nodejs express app (typescript, module: commonjs)

michaelprummer avatar Aug 13 '22 15:08 michaelprummer

I made a commonJS library for UCAN as a solution for this: https://npmjs.com/package/ucan-storage-commonjs

rhdeck avatar Aug 14 '22 18:08 rhdeck