How to clear node_modules cache in App Platform

I have a static site deployment that is built from a TypeScript+React app. Any time a deployment builds with a cached node_modules directory, I get a build error. Any time I change yarn.lock and force the app to be built, it succeeds.

My current theory is that I had a TypeScript build error present ~10 deployments ago ago due to an outdated @types/ package in devDependencies. I removed the package from package.json and yarn.lock which led to a successful build. The next build, containing only completely unrelated changes, failed with the error I had seen previously. Since then I have upgraded random packages to force yarn.lock to change and each time the build is successful. But each time a cached node_modules is used the build fails.

I’ve confirmed that this problem package, @types/history, is still in node_modules/@types/ in the cache (by adding ls node_modules/@types/ to my yarn build command). I’ve confirmed it is not in yarn.lock and if I nuke node_modules locally and yarn install locally it is not present.

How is node_modules caching done? If old caches are merged forward, then perhaps the outdated @types/ package is still present and thus breaking my TypeScript build.

Is there a way to delete the node_modules cache and start it over? Or to disable the use of the cache? Or, do you have advice for reproducing this issue locally? Thanks.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Here’s something that worked but it’s annoying:

"build": "rm -rf node_modules/@types/ && yarn install --check-files && GENERATE_SOURCEMAP=false react-scripts build",