urlcat icon indicating copy to clipboard operation
urlcat copied to clipboard

urlcat is not a function

Open alextes opened this issue 3 years ago • 4 comments

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 avatar Sep 08 '21 12:09 alextes

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.

alextes avatar Sep 08 '21 12:09 alextes

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

Devessier avatar Dec 22 '21 00:12 Devessier

This works:

import urlcatM from "urlcat";
const urlcat = urlcatM.default;

coder36 avatar Feb 04 '22 16:02 coder36

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?

alextes avatar Feb 15 '22 10:02 alextes

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

JasonLandbridge avatar Sep 25 '22 22:09 JasonLandbridge

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 🌞

alextes avatar Sep 26 '22 07:09 alextes

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 avatar Nov 12 '22 01:11 balazsbotond

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

gabrielsch avatar Jan 17 '23 15:01 gabrielsch

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

balazsbotond avatar Jan 17 '23 17:01 balazsbotond

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 avatar Jan 17 '23 18:01 balazsbotond

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

balazsbotond avatar Jan 17 '23 19:01 balazsbotond

@balazsbotond

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

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

allcontributors[bot] avatar Jan 17 '23 19:01 allcontributors[bot]