r/javascript • • Nov 30 '16

Modern JS developer workflow makes me sad

Edit:

Wow, I would never have expected so many replies and advises. I sincerely thank you all!

I would like to highlight 3 tips that have helped me the most:

  • @sdihgusdoiu - Hard Source Webpack Plugin. This plugin was rarely given a mention in other links given what a difference it makes and how simple it is to set up compared to other solutions.
    My mental model: it calculates a hash for Webpack config and package.json. If neither a compilation unit nor the hashes changed, it reuses output of previous builds for that compilation unit.
    This results in a massive decrease in (re)build times. ~70s build became ~5s.
    I wish this would be built into Webpack itself, although I understand there are reasons why not.  
     

  • @acemarke - Definitely a subjective hint that many people will dislike: Use eval for source maps in Webpack
    Not only is it by far the fastest option for Webpack to produce, the source it emits is what the browser actually executes. No more brain-dead breakpoint jumps by Dev Tools. Now you are free to copy-paste and play around with code directly from the Dev Tools.
    Yes, it does show an ugly transpiled code instead of your beautified ES6 + JSX, but it sounds much worse than it really is. Much more reliable and predictable than inline-source-map.  
     

  • @Retsam19 - for frequently used modules consider exporting them as globals using Expose loader
    Being able to dynamically REPL require(modulePath) for any module seems not to be possible, although there are some Stack Overflow answers claiming it is. I couldn't get them working
     


Original Post:

This post is partly a rant, partly a cry for help, partly an inquiry about any tips and tricks that could improve our day-to-day work.

My company adopted a new, modern JS stack; all pretty standard:

  • React

  • Babel ES6 + JSX

  • Redux

  • Mocha

  • Webpack

  • React Router

  • lodash

  • along with their 1262 transitive dependencies (I'm not kidding here!)

As a result, my daily productivity plummeted. Honestly, I feel like x86 Assembly must have a friendlier set of developer tools.

A non-exhaustive list of issues:

  • We used to laugh at Java guys with their sluggish Maven, at C++ compilation times.
    Nowadays it takes Webpack longer to build a todo app than for a complex Java project to download all dependencies, clean project, compile all files, run all tests, create a package and upload it to repository. npm is even worse

  • So...Webpack's hot reload, the mythical feature getting universal praise.
    Apart from the fact that "hot" means "after 5 or more seconds", it comes with the worst of both worlds - sometimes it does work, sometimes it just doesn't; with no indication whatsoever whether it succeeded or not. So you spend 2 minutes figuring out why your fix didn't work, only to find out it hasn't been deployed in the first place. A colleague of mine stated: "I just don't trust hot reload. I always reload the entire page"

  • Webpack or Babel or something comes with a special, depression inducing feature: if you make a syntax error in your file, instead of displaying a clear error, it loads some random cached build from half a day ago

  • my employer can definitely find a better use for its money than me tracing build bugs of some deeply nested transitive 3rd party library that whimsically has changed it's AMD/UMD exports

  • so...source maps. I can see my original sources in Developer Tools! Usually, that is. So, let's try to add a debug breakpoint to my code!
    If you are lucky, it will stay on the line you clicked. Other times, it jumps a few lines up or down. Occasionally, it jumps to the bottom of the file. When developer tools sense that you haven't been frustrated for full 10 minutes, the breakpoint jumps to a 200kLoC app.js file, which freezes the entire Dev Tools and Chrome with it. Now, don't close Chrome at this point! If you do so, the next time you open Dev Tools, it will try to reopen the last session and freeze again. Just wait patiently for 2 minutes till Dev Tools finishes parsing the file, grab a cup of coffee. Actually, an antidepressant might be a better choice.

  • you won a lottery and Dev Tools really did stop at your breakpoint. Congrats,. Now, let's inspect some expression. Uncaught ReferenceError: X is not defined. What? Well, Babel thinks the best way to compile this piece of code:
    moment.isDate(...)
    is to translate it to:
    _moment2.default.isDate(...)
    This is done to every ES6 import. And yes, that "2" in _moment2 can and will change to "3" or just disappear, at any point.

  • Let's write some tests. Hm...they failed, let's see what's happening. Well, Chrome executes your test before it loads your sourcemaps, so it totally ignores your breakpoints. Remember that 200kLoC app.js file? That's your best bet now.

  • One of the best features of Javascript was an interactive REPL console in the browser. But that's so 2014! With Webpack/Babel, it's just not possible to get a reference to a particular module from Dev Tools Console. By design. Because best practices, man!

  • On the other hand, we have the 8th Wonder of the World, a time-travelling debugger for Redux. Last time I productively used it was never.

 

Is this...normal?  

How do you cope it?  

How is this clusterfuck touted as a state of the art in Javascript?  

Did you also become alergic to the phrase

makes it easy to reason about

 

516 Upvotes

292 comments sorted by

View all comments

12

u/[deleted] Nov 30 '16 edited Nov 30 '16

All these are the problems I worry can happen any time I bring in a new technology into a project. That is why I add things one at a time, and only use them in such a way that they encourage deeper understanding of it. I shy away from the features that do lots of magical things for me until I am ready to understand them. Each new thing you bring into a project will bring problems along with it. Along the way you have to take time to address each issue as it comes up, not just keep moving along because of deadlines. If you can't figure out how to address a particular issue, you have to decide if it is worth it to keep using that thing.

I would suggest you talk to the other devs at your company and see if they are having the same problems. Take time to address each problem one by one.

I tend to distrust claims about a technology solving a problem that I normally see failing all over the place. Webpack sounds really sketchy to me. Not that they are the same thing, but it reminds me of a problem I recently had. I am not using webpack, but this experience reminds me that browsers and the web and downloading resources are still very unreliable in general. I just did a new release to a website the other day, and when I visited it after deploying, the HTML and stuff was all messed up because of caching. I had to do a force refresh. Browsers haven't even figured out how to only use cached stuff when the online resource is not newer... How that is considered acceptable or better than not caching at all is completely beyond me. If you updated a non-HTML application and only parts of it updated and other parts of it used old code, and the behavior was not right, and you were told "Oh don't worry that is not our fault that happened. It is just some caching the OS does to keep your apps running faster, you have to press (insert keyboard shortcut here) to clear the cache once in a while", how well would that go over with you? But for some reason we are ok with it on the web... Also, any technology that helps you to sync anything will probably fail constantly. Why do I say this? I have never used any program that auto syncs anything that did not constantly do bad things and frustrate me. I'm not talking about programming tools, I'm just talking about end user applications.

My point is, it is better to stick with the lo-tech/old/roll your own mentality until you understand how/if you should use some newfangled thing. Don't get me wrong, I love newfangled things. I just insist on understanding them before relying on them / deploying code that uses them.

So here are some alternatives I would recommend exploring if you can't fix these issues. Get your company to adopt a rule about what browsers they will support. Normally it is ok to say you only support the major browsers that are auto-updated and then just assume your users keep theirs updated. Then instead of using transpilers, only use javascript features that work in those browsers. Then you don't need source maps and debugging should be easier. Although you might need to introduce some tool that scans your code for the javascript features you are not supposed to use...

As others have suggested, try using yarn instead of npm. I don't know if that will really solve any of your problems, but people seem to think yarn is mostly better at most things.

If yarn is still too slow because of too many dependencies, well maybe you should roll your own versions of some of these. The basic concept behind redux is simple enough that you should be able to make a simple version of it yourself. The massive explosion of dependencies has me concerned that most websites are simply insecure now. How many companies really make sure all their dependencies are up to date, and make sure those dependencies are ok to use because they are using up to date dependencies? How many companies actually look into if any of these dependencies have known security issues? Sometimes it is better just to roll your own and keep your dependencies low. Now as far as security related features you are probably better off using a trusted tool instead of rolling your own, but check out its' dependencies.

Also, you seem to be in the mood to enjoy this commentary on being a programmer: https://www.youtube.com/watch?v=MticYPfFRp8

10

u/goodwid Nov 30 '16

Browsers haven't even figured out how to only use cached stuff when the online resource is not newer

There are only two hard problems in computer science: Naming things, cache invalidation, and off-by-one errors.

3

u/marosurbanec Dec 01 '16

The thing is...what you recommend is indeed the way we did our job 2 years ago. We did develop UIs that our customers loved, on time and on budget.

Since then, UI side of our company has been overrun by hipsters and cool kids more interested in the newest tech blog post than in solving real customers' needs. 2-3 grumpy old experienced developers can't outshout 20 cool kids pitching about "developing in future stack now", on "npm and Github, the biggest and the fastest growing community".

2

u/SamSlate Nov 30 '16 edited Nov 30 '16

Amature here, what is the caching problem for html, exactly? I add a version paramameter (ie src="web.com/js/file.js?v=*{versionNumber}*") to all js/css files so they're always updated by all user's browser when the page has changed. Maybe you're describing a different issue?

2

u/[deleted] Dec 07 '16

I think you just solved all my caching woes... Thanks!

1

u/SamSlate Dec 07 '16

glad to hear it! =)

0

u/djslakor Dec 01 '16

Webpack sounds really sketchy to me.

Well then, that settles it. It "sounds really sketchy".

Have you ever used it ?

It's amazing how many developers are dishing terrible advice in this thread because they're unable/unwilling to keep up.