Hacker News new | ask | show | jobs
by smt88 1682 days ago
Import in JavaScript is significantly more varied and complex than import in any other language I know about.

There are multiple historical module systems, various official and unofficial syntaxes, and also the require keyword.

It is an absolute mess. I don't know anyone who understands all of the various flavors.

4 comments

On top of this, a lot of the tooling is just shit. I don't just mean it makes design decisions I disagree with (which is also true of e.g. Maven, or Bundler) or that they're lacking in niceties (e.g. every C development workflow), I mean it's just absolutely poorly implemented CADT-except-they're-actually-25-and-overcapitalized trash.

Yarn blew NPM away on speed with more features and nicer developer workflow. Webpack is on major version 5 and still everyone just uses CRA rather than try to configure it by hand, but then nobody really knows how to debug CRA if something breaks. The entire babel stack is ridiculous. The dominant tools have just been so awful, for so long.

> Yarn blew NPM away on speed with more features and nicer developer workflow.

I dunno if it's still true, but for years into people saying "LOL use yarn, it's a better replacement for NPM" it was still really easy to find packages that broke under Yarn because it lacked some feature or other, or was skipping some obviously-a-good-idea sanity check that NPM did and so crashed rather than proceeding after adjusting its approach, or to venture slightly off the happy path of doing "yarn install" and running into features that yarn didn't support, but NPM did. A venture into the issue tracker in that time period was enlightening, and I don't just mean the sheer count, but digging into some of the issues and why they were happening.

[EDIT] in fact, in the agency I was at at the time, a kind of joke developed that a project wasn't fully underway until you'd been forced to replace Yarn with NPM.

You're saying Java & Maven/Gradle are simpler than even Nodejs or ESM workflows?
Maven and Gradle are build tools, similar to esbuild.

I was talking about import in JavaScript itself, not build tools or package managers.

Within the actual language, there isn't a universal syntax just to use a package. In Java, there is.

> Within the actual language, there isn't a universal syntax just to use a package.

There is. The issue is one of mindset. You recognize Maven and Gradle as belonging to a sort of "parastandard" set of technology, offering proprietary (albeit free/open source) glimpses of how one could conceivably solve the set of problems that they're meant to be used for, but when it comes to JS, you're elevating the parastandard stuff to the level of being part of "JS".

Neither CommonJS nor NodeJS's `require` nor package.json nor TypeScript nor esbuild are part of JS. You shouldn't give them any privileged status that you aren't willing to give to Maven or Gradle when you think of Java.

I think you're misunderstanding what I'm saying. You're still talking about package managers and build systems. I'm talking only about syntax. TypeScript, NPM, esbuild, Gradle, and Maven are completely separate from what I'm talking about.
I'm not misunderstanding. (The difference between parastandard tech like package managers vs base-level stuff in e.g. the language itself was actually the point of my message, so I understand the distinction.) You're saying that unlike Java, JS at the language level doesn't have imports, but what you're saying is untrue.

It's entirely possible that the projects you're most familiar with aren't using them, but the JavaScript language has native modules, including standardized syntax and semantics for import statements.

Yes, I know JavaScript has native modules at the language level, but they are not universally supported.

Most importantly, there can't/won't be a breaking change for the previous iterations of module import, so we will continue to have many different ways to import.

It's not an issue of whether JS has a "blessed" way of doing it (and it didn't even have that for a long time). It's that there's more than 3 ways to do it, and many of them look similar and have confusing conflicts with compilers/packagers.

Maven and Gradle have been around for years, and they are pretty much understood.

Moreover, you can skip them entirely and roll your own in a couple of hours [1]

Meanwhile in JS world? Build tools now change faster than frameworks, and not a single person is concerned with upgrade paths, or working in tandem with other tools.

And yes, import story is a mess.

[1] https://tonsky.me/blog/python-build/

After struggling to comprehend JS import and modules as much as I did as a single dev, I concluded that it’s my fault - that there’s something wrong with me.

I had to read the MDN guides multiple times and still need to refer to them.

Setting the build system part for my new projects is still the most challenging task.

Why do I have to learn how to build a grand piano every time I want to play a simple melody?

require ‘thing’ in Ruby requires the thing and that’s it.

require in JS should be use i. Node but not in the browser if I remember? Or maybe not? I don’t know, I guess I’ll just try things y til it works.

Python?
Python's packaging infrastructure is a mess, but the even the _environment_ surrounding import, let alone the module semantics, largely hasn't changed since the introduction of venv.

For all the other failings of the Python 3 migration, the Python community strongly and rightly rejected 2to3 which would've eventually produced a babelesque mess if continued.

I think you may be referring to package management rather than the import syntax of the language.