Open joshkel opened 4 months ago
I think it's time to do something to make memoize-one
have a fantastic esm story
How do you feel about an approach like this? (It's from a WIP package i've been working on)
https://github.com/alexreardon/limit-once/blob/main/package.json#L20-L25
How do you feel about an approach like this? (It's from a WIP package i've been working on)
https://github.com/alexreardon/limit-once/blob/main/package.json#L20-L25
Very reasonable imo
Ran into this exact issue today when trying to move some services to esm
According to Are the Types Wrong, memoize-one has an incorrect default export.
This can cause errors with TypeScript, depending on tsconfig.json settings. For example:
"type": "commonjs"
) and tsconfig.json"module": "node16", "moduleResolution": "node16"
, then everything works."type": "module"
) and tsconfig.json"module": "node16", "moduleResolution": "node16"
, problems arise:memoizeOne
directly, the TypeScript compiler throws an error at compile time:.default
, you get an error at runtime:As I understand it, there are two possible solutions:
.d.ts
file that reflects the CommonJS export assignment approach used by the Rollup-generated memoize-one build. (There may be a way to get tsc to do this for you, but I haven't been able to figure it out.) I believe that this could be done in a semver-patch release.exports
(so Node.js, and TypeScript when usingnode16
module resolution, can see it), with ESM-specific types. This may be a semver-major change.If you're interested in one of these approaches, I can try and open a PR.