Live data from Hacker News

A one-line package broke `npm create-react-app`

github.com

41–50 of 478 posts

Re: A one-line package broke `npm create-react-app`

#41
post #6

Earlier quoted context omitted.

I don't know how "clickbait" that title can be when it is, in fact, longer than the line of code in question: declare function isPromise (obj: Promise | S): obj is Promise ; This is, indeed, the only line of exported code in the entire package. I genuinely don't understand the NPM world.

Me neither. I can't wait for Deno 1.0 next month. https://deno.land/

Makes me look forward to this more https://romejs.dev/ since one of the ideas is that it will have no third party dependencies...

Re: A one-line package broke `npm create-react-app`

#43
Everyone crying about this on the Internet would do better to just take it as an easy lesson: pin your dependency versions for projects running in production.

This was an honest oversight, and even somewhat inevitable with so many expected supported ways to import/export between cjs mjs amd umd etc. It will happen again.

And when it happens the next time, if it ruins your life again, take issue with yourself for not pinning your dependency versions, rather that package maintainers trying to make it all happen.

Re: A one-line package broke `npm create-react-app`

#45
post #7

And the source code of the library is: function isPromise(obj) { return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; }

Here's my off-the-cuff take that will not be popular.

A function like this should be a package. Or, really, part of standard js, maybe.

A) The problem it solves is real. It's dumb, but JS has tons of dumb stuff, so that changes nothing. Sometimes you want to know "is this thing a promise", and that's not trivial (for reasons).

B) The problem it solves is not straightforward. If you Google around you'll get people saying "Anything with a .then is a promise' or other different ways of testing it. The code being convoluted shows that.

Should this problem be solved elsewhere? Sure, again, JavaScript is bad and no one's on the other side of that argument, but it's what we have. Is "just copy paste a wrong answer from SO and end up with 50 different functions in your codebase to check something" like other languages that make package management hard so much better ? I don't think so.

Re: A one-line package broke `npm create-react-app`

#46

Earlier quoted context omitted.

My prior decision to never work with JavaScript again has just grown firmer.

I second this, JavaScript Devs are near the bottom of the food chain, just above VB Devs. Myself as a Java developer is middle of the pyramid. The apex predators are embedded developers, followed by c Devs then game Devs.

It's not useful, interesting, or accurate to stratify people this way. You have no idea what someone's intelligence level or background is based on their usage of JS or C.

I loathe JS, but one of the best devs I know likes it. People's mileage varies.

For me personally, there's much more money in easy React products than making games. I'm not a great dev, but I'd be doing this same work even if I were.

Re: A one-line package broke `npm create-react-app`

#47
post #25
post #6

Earlier quoted context omitted.

I don't know how "clickbait" that title can be when it is, in fact, longer than the line of code in question: declare function isPromise (obj: Promise | S): obj is Promise ; This is, indeed, the only line of exported code in the entire package. I genuinely don't understand the NPM world.

NPM is the answer to the question: what would happen if everyone refused to use any idioms ever, and instead replace them all with packages? God help you, if you import a JavaScript (or Rust) package today. Lest you fall in a gaping chasm of endless cascading dependencies.

It's not NPM's fault, it's developer's fault.

I would never in my right mind publish a one-line package, Python, Javascript, whatever.

And I would never add a one line package as dependency

Re: A one-line package broke `npm create-react-app`

#49
I think these one-line-packages aren't the right way to go. Either JS-developers should skip the package-system in that case and just copy and paste those functions into their own project or there should be more common used packages that bundle these one-liners. I mean is_promise() and left_pad() are not worth their own package. Packages-dependencies of 10000 packages for trivial programs are just insane.

Is someone going to fix that?

Re: A one-line package broke `npm create-react-app`

#50
post #7

And the source code of the library is: function isPromise(obj) { return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; }

Wow just wow. So here's your new Promise object:

class World { then () { return 0; } } isPromise(new World) // true

If there really isn't a safe and better way to tell if an object is an instance of Promise…then color me impressed.

Post reply on HN