Tuesday, May 5, 2026

Dead‑On‑Chair Debug Snafu: How My NestJS App Starved on Shared Hosting and Finally Fixed the “Module Not Found” Error Without Re‑Deploying It In Slow Water‬

Dead‑On‑Chair Debug Snafu: How My NestJS App Starved on Shared Hosting and Finally Fixed the “Module Not Found” Error Without Re‑Deploying It In Slow Water

If you’ve ever stared at a blinking console, feeling the heat rise as your NestJS app throws “Module not found” over and over, you know the panic that comes with a production‑grade bug on a cheap shared server. I’ve been there—late night, coffee‑stained keyboard, and a hosting account that feels more like a leaky bucket. In this post I’ll walk you through the exact steps I took to rescue a starving NestJS app, fix the missing‑module nightmare without a costly redeploy, and get the site back up while keeping the bill low.

Quick hook: By the end of this tutorial you’ll know how to diagnose hidden file‑system limits, apply a one‑line fix, and automate the fix for future releases—saving you hours of downtime and a few hundred dollars.

Why This Matters

Shared hosting is the cheap entry point for freelancers, side‑hustlers, and small SaaS founders. It’s cheap, but it comes with strict inode limits, read‑only directories, and a “slow water” environment where every I/O call feels like wading through mud. When your NestJS monorepo deploys a new node_modules folder, the host can silently refuse to write the new files, leaving your app with broken imports. The result? A Cannot find module ‘@nestjs/core’ error that looks like a code bug, but is really a hosting‑capacity problem.

Step‑by‑Step Tutorial

  1. Check the inode and disk quota

    Log into SSH (or use the host’s file manager) and run:

    df -h .
    du -h --max-depth=1 .
    find . -type f | wc -l   # counts inodes

    If the inode count is near the limit (often 100,000 on cheap plans), Node can’t create new files in node_modules. This is the hidden cause of the “Module not found” error.

  2. Free up space without deleting source code

    Delete old log files, caches, and any unused Composer or pip packages:

    rm -rf /home/username/logs/*.log
    rm -rf /home/username/tmp/*
    find . -name "*.cache" -delete

    Keep the src and dist directories intact – they’re the heart of your app.

  3. Create a “node_modules cache” outside the public root

    Many shared hosts allow a ~/private folder that isn’t counted against the web root quota. Move the heavy node_modules there and symlink it:

    # Move modules
    mv /home/username/www/node_modules /home/username/private/node_modules
    
    # Symlink back to the app
    ln -s /home/username/private/node_modules /home/username/www/node_modules

    This trick tricks the host into believing the files live in a “safe” area while your app still finds them where it expects.

  4. Patch the runtime loader (no redeploy)

    If the app is already running, you can hot‑swap the broken path by editing webpack-prod.js (or the equivalent tsconfig.json path mapping). Add a fallback that points to the symlinked folder:

    // webpack-prod.js
    module.exports = {
      // ...other config
      resolve: {
        modules: [
          'node_modules',
          '/home/username/private/node_modules' // <--- added line
        ],
      },
    };

    Then restart the process (most shared hosts use pm2 restart ecosystem.config.js or just “restart” from the control panel). No new build, no new upload.

  5. Verify the fix

    Run the health endpoint or simply curl the app:

    curl -I https://yourdomain.com/health
    # Expect: HTTP/1.1 200 OK

    If you see a 200 response and the console no longer logs “module not found”, you’re good to go.

Tip: Add the symlink command to a post‑install script in package.json so every future npm install on the host runs it automatically.

Real‑World Use Case: A SaaS Dashboard on Shared Hosting

My client ran a NestJS‑backed admin dashboard for a tiny e‑commerce site. The site was on a $4.99/month shared plan, and once a month the host ran a clean‑up that deleted unused inodes. That night the dashboard threw “Cannot find module ‘@nestjs/typeorm’”. Using the steps above, we:

  • Freed 12 GB of old log space.
  • Moved node_modules to ~/private.
  • Patched the webpack config on the fly.
  • Restored full functionality in under 15 minutes.

The client saved $3,000 in potential lost sales and avoided a $100 upgrade to a VPS.

Results / Outcome

After the fix:

  • Uptime: 99.97% for the next 30 days.
  • Page load: 0.9 s average (unchanged, no extra latency from the symlink).
  • Cost: No additional server spend.
  • Developer time saved: ~4 hours of debugging turned into a 15‑minute fix.

Bonus Tips

  • Monitor inode usage with a cron job that emails you when you hit 80%.
  • Compress static assets (images, CSS) with gzip to free up more space.
  • Use npm ci instead of npm install for reproducible builds that skip optional dependency bloat.
  • Consider a read‑only “vendor” folder on a CDN for large libraries – it reduces the host’s file count dramatically.
Warning: Never delete node_modules from the symlinked location while the app is running. Stop the process first, then clean and rebuild.

Monetization (Optional)

If you’re a freelancer, package this “Shared‑Host Rescue” service as a one‑time $199 fix or a $29/month monitoring plan. Many small business owners aren’t aware of inode limits, and they’ll pay for peace of mind.

“I thought I needed a whole new server. Turns out a few lines of config and a symlink saved me weeks of work.” – Happy client

Got stuck on a similar “module not found” on a cheap host? Drop a comment below, and I’ll help you troubleshoot. Remember: the fastest fix is often not in your code—but in the environment around it.

No comments:

Post a Comment