alexreardon / memoize-one

A memoization library which only remembers the latest invocation
MIT License
2.93k stars 77 forks source link

"This expression is not callable" type error when trying to use this package from ESM module #265

Closed kaiyoma closed 1 year ago

kaiyoma commented 1 year ago

I've been using memoize-one from CJS for many years, but when I try to convert the calling code to ESM, I now get this error:

src/lib.ts:73:21 - error TS2349: This expression is not callable.
  Type 'typeof import(".../common/temp/node_modules/.pnpm/memoize-one@6.0.0/node_modules/memoize-one/dist/memoize-one")' has no call signatures.

I'm pretty sure my import is correct:

import memoizeOne from 'memoize-one';

I'm not getting this error with any other dependency, so it seems specific to memoize-one. My package still builds correctly, which means it's maybe just an error with the types. I'm using the latest version (6.0.0).

kaiyoma commented 1 year ago

Switching to Vite/Vitest (away from webpack/Jest) fixed this issue for me.

samhh commented 8 months ago

I'm seeing the same with typechecking with "moduleResolution": "Node16". You can workaround it like so:

import _memoizeOne from 'memoize-one';

const memoizeOne = _memoizeOne as unknown as typeof _memoizeOne.default;