decentralized-identity / ethr-did-resolver

DID resolver for Ethereum Addresses with support for key management
Apache License 2.0
212 stars 77 forks source link

Added exports.types for ESM compatabilit #169

Closed RobertoSnap closed 2 years ago

mirceanis commented 2 years ago

I was actually just working on this :)

Are you able to test it from ethr-did-resolver@7.0.0-alpha.1 ?

RobertoSnap commented 2 years ago

haha, I published a version here: https://www.npmjs.com/package/@symfoni/ethr-did-resolver. Types working, but its not "native" ESM. I have to dynamically import the module.

Same with ethr-did-resolver@7.0.0-alpha.1

RobertoSnap commented 2 years ago

Message im getting:

CleanShot 2022-10-13 at 15 42 51

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("ethr-did-resolver")' call instead. To convert this file to an ECMAScript module, change its file extension to '.mts' or create a local package.json file with{ "type": "module" }.ts(1479)

mirceanis commented 2 years ago

From what I can figure, you're seeing that error because you're trying to import esm into a commonjs file.

I think this should be expected if ethr-did-resolver were pure-esm.

The problem is that it should actually be a commonjs build that also exposes an esm wrapper, so the bug is that ethr-did-resolver doesn't build as commonjs.

Do you have a project showing this error?

mirceanis commented 2 years ago

@RobertoSnap can you try to use ethr-did-resolver@7.0.0-alpha.2 ?

It should present 2 entry points now: the library built as a commonjs module and a wrapper for esm.

In alpha.1, both artifacts were in fact esm

RobertoSnap commented 2 years ago

From what I can figure, you're seeing that error because you're trying to import esm into a commonjs file.

I think this should be expected if ethr-did-resolver were pure-esm.

The problem is that it should actually be a commonjs build that also exposes an esm wrapper, so the bug is that ethr-did-resolver doesn't build as commonjs.

Do you have a project showing this error?

Yea, soon. Testing pure ESM but switching to commonjs too see effect of changes so maybe got it while i had switched 😬

@RobertoSnap can you try to use ethr-did-resolver@7.0.0-alpha.2 ?

It should present 2 entry points now: the library built as a commonjs module and a wrapper for esm.

In alpha.1, both artifacts were in fact esm

Will give it a try 👍

RobertoSnap commented 2 years ago

And what did you do to resolve the .json import in:

import { default as EthereumDIDRegistry } from './config/EthereumDIDRegistry.json';

RobertoSnap commented 2 years ago

@RobertoSnap can you try to use ethr-did-resolver@7.0.0-alpha.2 ?

It should present 2 entry points now: the library built as a commonjs module and a wrapper for esm.

In alpha.1, both artifacts were in fact esm

Yea, getting error with

Cannot find module './config/EthereumDIDRegistry.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.

From what i read about ESM, it cannot resolve .json 🤷‍♂️ https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

RobertoSnap commented 2 years ago

Hemm, nevermind. I reset config and it works now on ethr-did-resolver@7.0.0-alpha.2

RobertoSnap commented 2 years ago

Closed as @mirceanis allready working on a version of ethr-did-resolver@7.0.0-alpha.2

Will open issue with other ESM stuff