urlcat
urlcat copied to clipboard
urlcat is not a function
Describe the bug locally runs fine, in a docker build my code blows up with "urlcat is not a function".
Node v16. I run in ESM mode.
minimal example is create a ts project with module ES2020, run with node v16 type: "module".
import urlcat from "urlcat";
urlcat("", "")
results in the "not a function" type error. I tried import {default as urlcat} from "urlcat"
too.
any idea what could be happening? I really like this module!
this solves it for me, perhaps it can help others or even update the imports so they work with ts/ESM.
import urlcatM from "urlcat";
const urlcat = (urlcatM as unknown as { default: typeof urlcatM }).default;
import {default as urlcat} from "urlcat";
still needs the same .default
to fix things.
Thanks @alextes, I encountered the same issue with my SvelteKit blog, and indeed, it works!
This works:
import urlcatM from "urlcat";
const urlcat = urlcatM.default;
This is getting annoying 🙁 . This is a great lib but importing it is kinda the minimum, and it doesn't work with the modern TS + ESM setup (unless I'm missing something). Can someone make me a maintainer so I can try to fix it?
@balazsbotond , could you maybe assign @alextes as an maintainer? It would be a shame if this project dies a silent death.
I see some 👍 have piled up 😅 . For others in need, I wrote a lib that does the bare minimum.
https://github.com/alextes/url-sub
I wouldn't recommend getting behind that one however, it's a stop-gap, looking at this issue again and the great-looking source for this lib, someone should just fork this and make the exports work. I am a little short on time.
I think two libs that give a good example of what the exports could look like are:
- https://github.com/gvergnaud/ts-pattern (for combined ESM / CJS exports)
- https://github.com/sindresorhus/p-queue (for ESM only, after all, this lib works fine for CJS)
Have a great day coders 🌞
Hi everyone, sorry for the long hiatus. I'm now reading through all the issues and trying to resolve them. This seems to be the most urgent problem with the project - please let me take some time to understand it and come up with a solution. PR's are also very much appreciated. Thank you for your patience!
@balazsbotond PR implementing ESM support and interoperable CJS: https://github.com/balazsbotond/urlcat/pull/232
@gabrielsch thank you for the PR! I will review it soon.
Thank you everyone for your patience and @gabrielsch for the PR. I've just released v3.1.0 which now supports both CJS and ESM modules.
@all-contributors please add @alextes for bug. please add @gabrielsch for ideas and code.
@balazsbotond
I've put up a pull request to add @alextes! :tada:
I've put up a pull request to add @gabrielsch! :tada: