9

I might be new to webdev , but wtf is wrong with imports in js ?

html seems to get the only decent way of dealing with js: all the files mentioned in subsequent <script> tags can access the functions of previous file

but when it comes to those generated html content(aka react projects) and servers, nobody seems to come to an agreement : react guys uses import while server people uses require. and both of these can't be used in the same file : import works in mjs files (or usual files too if type is defined as module) while require works in cjs file (or usual js files if type is NOT defined as module)

so i kind of like imports for its elegance and resembelence to java imports. and i might have got into some errors in unrelated areas , so my package.json has type=module . i want to use some cjs package (jsonwebtoken) and that shit for the love of god won't work with import, so i gotta use it with cjs file and then the whole project can't use that crappy cjs file.

WTAF ? has web world not got matured enough to not have this shitty import export situation?should i write caveman code and convert everything to require(..) ?

fuck me

Comments
  • 7
    Web is a shit show of "I can do it better" but every framework then allows for "but I want to do it my way" which creates a clusterfuck of discrepancy and redundancy in how and why you do things.

    React is hard, angular is harder, vue is some weird ass hybrid that got it wrong.

    The web is a mess, I apologise that you showed up so late into this field and get to see first hand what all the commotion is about.
  • 0
    This is the result of having a shitty tool (JS) forced on everyone. Forces people to polish the turd to absurd levels, but there is no clear way to improve it because it sucks so much, so you have a million alternatives that are all terrible in different ways.
  • 1
    Use Typescript. It fixes other problems that you definitely have because they're intrinsic to programming, but it also allows you to write ES imports and then compile down to both ES modules and CommonJS.
  • 0
    But yeah, the tragedy of JS is that much like C it got standardized without an infrastructure and ended up with five, but unlike C it wasn't initially meant to be a real language so trivial shit like multi-file assemblies were missing from the standard during the boom.
  • 1
    @C0D4 I mostly agree but i do think that Angular is easier than React.

    Svelte is easier than both but i seldom use any of these things if i get the chance
  • 0
    @AleCx04 react has slowly grown on me. Still a clusterfuck though.

    Plus it's become the standard at work with other teams, so.. a tad hard to avoid it.
Add Comment