-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Which package?
@formatjs/fast-memoize
Describe the bug
The main property of @formatjs/fast-memoize is a CommonJS module that specifies module.exports.default. There is no (real) ESM support. That means that usage in CommonJS is as follows:
const memoize = require('@formatjs/fast-memoize')
memoize.default(/* … */)and usage in ESM is:
import memoize from '@formatjs/fast-memoize'
memoize.default(/* … */)IMO this is not pretty, but it works.
The problem is that @formatjs/fast-memoize does specify the module field. This points to a faux ESM module. Many bundlers use this field, so correct use with a bundler is:
import memoize from '@formatjs/fast-memoize'
memoize(/* … */)This means it’s not possible to use @formatjs/fast-memoize in isomorphic code.
To Reproduce
Codesandbox URL
N/A
Reproducible Steps/Repo
- Create the following script named test.mjs:
import memoize from '@formatjs/fast-memoize'; console.log(memoize); ``
- Run the following script using Node.js:
node test.mjs
Notice that memoize is a module with the property default. memoize itself is not a function.
Expected behavior
I would expect at least one of the following:
@formatjs/fast-memoizesupports proper dual packaging using package exports.@formatjs/fast-memoizeremoves support for CommonJS.@formatjs/fast-memoizeremoves support for faux ESM.@formatjs/fast-memoizeuses a named export instead of a default export.@formatjs/fast-memoizegets deprecated in favour offast-memoize.
A clear and concise description of what you expected to happen.
Screenshots
N/A
Desktop (please complete the following information):
- OS: Pop!_OS
- Browser: Node.js
- Version: 18
Smartphone (please complete the following information):
- Device: N/A
- OS: N/A
- Browser N/A
- Version N/A
Additional context
@formatjs/fast-memoize was created because of a very niche issue (#1913). fast-memoize uses CommonJS (not UMD, as is claimed in that issue). Node.js native ESM and bundlers can consume CJS just fine. A lot of ESM packages have CJS dependencies.