caxa
caxa copied to clipboard
default export does not work as expected
In a *.js file (CommonJS)
const caxa = require('caxa')
caxa(...).catch(err => console.log(err.message))
results in: ERROR, caxa is not a function
The same is true for a *.mjs (ESM) file with import syntax.
Instead, this works for me:
const caxa = require('caxa').default
caxa(...).catch(err => console.log(err.message))
Yeah, I’ve noticed this before. I played around with different tsconfig.json fields and different ways to export from TypeScript, and I Googled around, but found no way to fix this. Do you know what’s wrong?
I encountered the same issue while using the ESM import syntax
import caxa from 'caxa';
await caxa(...)
results it ERROR: TypeError: caxa is not a function
The workaround is:
import caxa from 'caxa';
await caxa.default({
...
})
It seemes that caxa, instead of being a function, it's an object with a default property which is the actual function
import caxa from 'caxa'
console.log(caxa);
resulted in { default: [AsyncFunction: caxa] }.
Hope these information could help you figure out which may be the issue
Thanks for the information.
I learned that there are two solutions to this:
- Transform caxa into an ESM-only package. This is the approach I’ll be taking soon.
- Create a dummy file that re-exports
caxa.default. This is mostly for backwards compatibility with RequireJS.
Hi y’all,
Thanks for using caxa and for the conversation here.
I’ve been thinking about the broad strategy employed by caxa and concluded that there is a better way to solve the problem. It uses ESM, but it doesn’t include a programmatic API, it’s CLI-only.
It’s a different enough approach that I think it deserves a new name, and it’s part of a bigger toolset that I’m building, which I call Radically Straightforward · Package.
I’m deprecating caxa and archiving this repository. I invite you to continue the conversation in Radically Straightforward’s issues.
Best.