DEV Community

Kyle Y. Parsotan
Kyle Y. Parsotan

Posted on

🚨 Common React & npm Bugs (and How to Fix Them Like a Pro)

Every developer hits weird errors. The difference between struggling for hours vs fixing things fast comes down to pattern recognition.

This post breaks down well-known bugs, why they happen, and how to fix them quicklyβ€”especially in projects using Create React App and the Node ecosystem.


🧨 1. react-scripts: command not found

❌ Error

sh: react-scripts: command not found
Enter fullscreen mode Exit fullscreen mode

πŸ’₯ Why it happens

  • react-scripts isn’t installed
  • node_modules is missing/corrupted
  • Wrong project directory

βœ… Fix

rm -rf node_modules package-lock.json
npm install
Enter fullscreen mode Exit fullscreen mode

If still broken:

npm install react-scripts
Enter fullscreen mode Exit fullscreen mode

πŸ” 2. EACCES Permission Denied

❌ Error

EACCES: permission denied, mkdir 'node_modules/.cache'
Enter fullscreen mode Exit fullscreen mode

πŸ’₯ Why it happens

  • You used sudo npm install
  • Files are owned by root

βœ… Fix

sudo chown -R $(whoami) .
rm -rf node_modules package-lock.json
npm install
Enter fullscreen mode Exit fullscreen mode

🚫 Never use:

sudo npm install
Enter fullscreen mode Exit fullscreen mode

πŸ“¦ 3. node_modules Hell (Corrupted installs)

❌ Symptoms

  • Random errors after install
  • Missing packages
  • App won’t start

πŸ’₯ Why it happens

  • Interrupted installs
  • Lockfile conflicts
  • Cache issues

βœ… Fix (golden reset)

rm -rf node_modules package-lock.json
npm cache clean --force
npm install
Enter fullscreen mode Exit fullscreen mode

⚠️ 4. Version Mismatch (Node issues)

❌ Symptoms

  • Packages fail to install
  • Build crashes
  • Strange syntax errors

πŸ’₯ Why it happens

Some tools don’t support newer Node versions.

βœ… Fix

node -v
Enter fullscreen mode Exit fullscreen mode

Use:

  • Node 18 or 20

Use a version manager if needed.


πŸ”„ 5. Mixing Package Managers

❌ Symptoms

  • Duplicate dependencies
  • Lockfile conflicts
  • Install failures

πŸ’₯ Why it happens

Using npm + yarn together.

βœ… Fix

  • Use ONE:

    • package-lock.json β†’ npm
    • yarn.lock β†’ yarn

🌐 6. Port Already in Use

❌ Error

Something is already running on port 3000
Enter fullscreen mode Exit fullscreen mode

πŸ’₯ Why it happens

Another process is using the port.

βœ… Fix

lsof -i :3000
kill -9 <PID>
Enter fullscreen mode Exit fullscreen mode

πŸ§ͺ 7. ESLint Permission Errors

❌ Error

EACCES: permission denied
Enter fullscreen mode Exit fullscreen mode

πŸ’₯ Why it happens

Same root cause: ownership issues.

βœ… Fix

sudo chown -R $(whoami) .
Enter fullscreen mode Exit fullscreen mode

⚑ 8. Module not found Errors

❌ Error

Module not found: Can't resolve 'xyz'
Enter fullscreen mode Exit fullscreen mode

πŸ’₯ Why it happens

  • Package not installed
  • Wrong import path
  • Case-sensitive file systems

βœ… Fix

npm install xyz
Enter fullscreen mode Exit fullscreen mode

Or fix import:

import Component from "./Component" // not ./component
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ 9. Environment Variables Not Working

❌ Symptoms

  • process.env is undefined

πŸ’₯ Why it happens

In CRA, env vars must start with:

REACT_APP_
Enter fullscreen mode Exit fullscreen mode

βœ… Fix

REACT_APP_API_URL=https://api.com
Enter fullscreen mode Exit fullscreen mode

Restart dev server after changes.


🧠 10. Outdated Tooling Problems

❌ Symptoms

  • Random build errors
  • Slow dev server
  • Weird dependency issues

πŸ’₯ Why it happens

Older tools like Create React App rely on aging dependencies.


πŸš€ Modern Fix (Long-Term)

Instead of constantly patching bugs:

Switch to:

  • ⚑ Vite
  • πŸ”₯ Next.js

Example (Vite setup)

npm create vite@latest my-app
cd my-app
npm install
npm run dev
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ Faster, fewer bugs, better DX.


🧠 Final Thoughts

Most β€œReact bugs” are actually:

βš™οΈ environment problems, not code problems

Once you recognize patterns like:

  • permissions
  • missing dependencies
  • version mismatches

You’ll debug 10x faster.


πŸ’¬ What bug are you stuck on?

Drop your error below πŸ‘‡
I’ll help you debug it step-by-step.

Top comments (0)