Closed TateB closed 1 year ago
how can I create an typescript project that experiences this issue?
set moduleResolution
in tsconfig to node16
or nodenext
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?
just created a minimal repo for it: https://github.com/TateB/normalise-barebones-typescript
pnpm install
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.
it works with require()
but as a modern lib shouldn't require it
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()
.
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.
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
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
although commonjs is currently exported, it has problems with typescript + commonjs resolvers as the package is defined as a module.
to fix:
type: module
from package.json.js
files to.mjs
.cjs
files to.js
module
in package.json toindex.mjs
exports
field