Software⏱️ 3 min read📅 2026-06-15

How to Fix: error from node js or npm when I open Ubuntu terminal

Error fixing Node.js and npm issues on Ubuntu.

Quick Answer: Try reinstalling Node.js and npm, or use a package manager like apt-get to install the necessary dependencies.

The error you're experiencing occurs when Node.js or npm cannot find the required modules, resulting in an error message. This issue affects users of Ubuntu and can occur after upgrading from older versions of Ubuntu.

This error is frustrating because it prevents users from running their applications and executing commands in the terminal. The solution involves identifying the root cause of the issue and applying one or more of the provided fixes.

⚠️ Common Causes

  • The primary reason for this error is related to the Node.js installation process on Ubuntu. When you upgraded your system, Node.js was not properly installed or updated, leading to a missing 'internal/modules/cjs/loader.js' file.
  • Alternatively, it's possible that the issue is caused by a misconfiguration of the system's file permissions or a conflict with other packages installed on the system.

🚀 How to Resolve This Issue

Reinstalling Node.js and npm

  1. Step 1: Open the terminal and run the command 'sudo apt-get update' to ensure that your package list is up-to-date.
  2. Step 2: Then, install Node.js using the command 'sudo apt-get install nodejs' or 'sudo apt-get install npm'. This may take a few minutes to complete.
  3. Step 3: After installation, verify that Node.js and npm have been successfully installed by running the commands 'node -v' and 'npm --version', respectively.

Resetting system file permissions

  1. Step 1: Open the terminal and run the command 'sudo chown -R $USER:$USER /home/$USER/'. This will reset the ownership of all files in your home directory to your current user.
  2. Step 2: Next, run the command 'sudo chmod -R u+x /home/$USER/'. This will change the permissions of all files in your home directory to allow execution by your user.
  3. Step 3: After resetting the file permissions, try running Node.js and npm again to see if the issue persists.

✨ Wrapping Up

To resolve the error you're experiencing, try one or both of the provided fixes. If reinstalling Node.js and npm doesn't work, attempting to reset system file permissions may help. If neither solution works, consider seeking further assistance from a Linux expert or the official support channels for Node.js and npm.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions