adraffy / ens-normalize.js

ENSIP-15 in JS
https://adraffy.github.io/ens-normalize.js/test/resolver.html
MIT License
63 stars 17 forks source link

Fix exports #14

Closed TateB closed 1 year ago

TateB commented 1 year ago

although commonjs is currently exported, it has problems with typescript + commonjs resolvers as the package is defined as a module.

to fix:

adraffy commented 1 year ago

how can I create an typescript project that experiences this issue?

TateB commented 1 year ago

set moduleResolution in tsconfig to node16 or nodenext

adraffy commented 1 year ago

I can't replicate the issue. I can require and import @adraffy/ens-normalize into a TS project using resolution node and nodenext without issue. What else am I missing?

TateB commented 1 year ago

just created a minimal repo for it: https://github.com/TateB/normalise-barebones-typescript

pnpm install

adraffy commented 1 year ago

Isn't this a CJS project? Works with require() or as-is with type: "module".

Replacing the code with import {open} from 'fs' will compile but fails to execute.

TateB commented 1 year ago

it works with require() but as a modern lib shouldn't require it

adraffy commented 1 year ago

so just to be clear, I'm not trying to be difficult or against applying this change, I'm just trying to understand it.

I'm under the impression that your projects ESM / CJS choice is independent of my projects ESM / CJS choice if I build both file types and link them correctly in package.json

https://github.com/TateB/normalise-barebones-typescript to me compiles as ESM but runs as CJS which seems misconfigured. It works correctly if changed to module or to require().

TateB commented 1 year ago

I'm under the impression that your projects ESM / CJS choice is independent of my projects ESM / CJS choice if I build both file types and link them correctly in package.json

this is true in theory, but in reality esm/cjs support across ts/node has a lot of weird quirks.

https://github.com/TateB/normalise-barebones-typescript to me compiles as ESM but runs as CJS which seems misconfigured. It works correctly if changed to module or to require().

sorry should have clarified the repo was just for the typescript type error. changing the module in the tsconfig to CommonJS doesn't remove the error.

TateB commented 1 year ago

https://github.com/TateB/normalise-barebones-typescript to me compiles as ESM but runs as CJS which seems misconfigured. It works correctly if changed to module or to require().

realised what you were saying here, i think type: module generally just causes awkwardness when consuming the pkg in a lot of apps (which is why you've had bug reports about it before). you're right in that it is misconfigured though. at this point this PR doesn't really matter, but will still solve the problem more easily for others in the future

adraffy commented 1 year ago

I think this is fixed in 1.9.1 by the latest Ricmoo change which drops type: module from the npm distribution and uses .mjs