'Apps' always builds Node app with cache node_modules despite changes to package.json

Posted December 20, 2020 1.4k views
DigitalOcean App Platform

Hello -

I am new to the Digital Ocean Apps platform and I am having an issue related to when the instance begins building my Node application. The issue is related to previously cached node_modules during the build process. I have added a few modules but builds via DO do not reflect these module changes, as DO continues to use a cached version of node_modules (as seen in the logs, I believe related to Docker and Buildpack?). The package-lock.json is checked in, but I am unsure if this would resolve the issue or not.

How do I clear this cache to ensure the DO environment does not use cached assets?

1 comment
  • @kamaln7
    Came across this and was also running into an issue where I was getting a ‘webpack: command not found’ error during my build, even though it was a required nodemodule. I ended up deleting my component and created a new one off the same commit, and it built successfully. Clearly something was off with the cached nodemodules - possibly because they were from several weeks ago?

    Anyway, is there a way that I can force a build without using cached node modules? Especially since my package-lock.json had quite a few changes. Deleting a component and recreating it is especially destructive and honestly is making me question whether this platform is mature enough to switch over to from a DO Droplet just yet.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

👋🏼 @JohnFoderaro

Looking at your app’s build logs, it seems to be using Yarn instead of NPM to install dependencies. If a yarn.lock file exists, App Platform will use Yarn, even if a package-lock.json file exists.

Make sure you commit the dependency updates to yarn.lock or remove it entirely if you don’t need it. This will invalidate the existing cache and install the right dependencies. Let me know if that works!

  • D'oh! Great find. This resolved my issue, as for this project we are preferring npm over yarn, so I removed that file and got beyond this issue (and right into a different, unrelated issue). Thank you!

    • Glad to hear! Feel free to follow up with the other issue if you get stuck :)

      • Thanks. I am actually stuck again 😅

        I keep running into an issue where I am having a non-zero exit code when running my production npm script. The gist of the script is 1) build webpack assets for client-side JavaScript and CSS and 2) run the Express server (this is not a React app or the like, just an Express app with some templating). The console shows the webpack build is successful and that the Express server starts - but then everything just sort of hangs and the DO builds fail. Should I be running a different script/command where this Express process is put into the background or something along those lines? I did try the above out with PM2 to execute the production script but nothing changed. This works fine locally (of course, lol). Thank you.

        • I’m trying to look at the deploy logs for your app. I don’t see any errors from PM2 but I believe it’s saving the app logs to a log file instead of piping to stdout/stderr, so that’s why they’re not visible in the logs.

          I assume building webpack assets is a one-off command? If that is the case, you can run it and then start Express directly without using PM2. So the run command would look like this:

          npm run build-webpack-assets && node index.js

          Since App Platform handles auto restarting crashed processes, you don’t need PM2 if you’re only running one command.

          Although, you might be able to move the building of webpack assets to the build command and then have the run command only start Express. That would be preferable if it works with your app.