@wordpress/api-fetch
works weirdly with ES modules
#59087
Labels
Good First Issue
An issue that's suitable for someone looking to contribute for the first time
[Package] API fetch
/packages/api-fetch
[Type] Bug
An existing feature does not function as intended
When using
@wordpress/api-fetch
in a TypeScript library,tsc
complains thatapiFetch
is not callable.The problem being encountered here is described in depth at https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/CJSOnlyExportsDefault.md
Example
package.json
tsconfig.json
src/index.ts
Run
npm install
, thennpm exec tsc
to attempt to build the "library".Expected results
Build succeeds
Actual results
Notes
If we change the
apiFetch()
call toapiFetch.default()
,tsc
is happy but then the code won't work when the library is bundled and served to a browser.To make things work in both environments, we needed to do something like this.
The text was updated successfully, but these errors were encountered: