balazsbotond / urlcat

A URL builder library for JavaScript.
https://urlcat.org
MIT License
1.82k stars 57 forks source link

urlcat is not a function #171

Closed alextes closed 1 year ago

alextes commented 3 years ago

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!

alextes commented 3 years ago

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.

Devessier commented 2 years ago

Thanks @alextes, I encountered the same issue with my SvelteKit blog, and indeed, it works!

coder36 commented 2 years ago

This works:

import urlcatM from "urlcat";
const urlcat = urlcatM.default;
alextes commented 2 years ago

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?

JasonLandbridge commented 2 years ago

@balazsbotond , could you maybe assign @alextes as an maintainer? It would be a shame if this project dies a silent death.

alextes commented 2 years ago

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:

Have a great day coders 🌞

balazsbotond commented 1 year ago

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!

gabrielsch commented 1 year ago

@balazsbotond PR implementing ESM support and interoperable CJS: https://github.com/balazsbotond/urlcat/pull/232

balazsbotond commented 1 year ago

@gabrielsch thank you for the PR! I will review it soon.

balazsbotond commented 1 year ago

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.

balazsbotond commented 1 year ago

@all-contributors please add @alextes for bug. please add @gabrielsch for ideas and code.

allcontributors[bot] commented 1 year ago

@balazsbotond

I've put up a pull request to add @alextes! :tada:

I've put up a pull request to add @gabrielsch! :tada: