DEV Community

TechFixDocs
TechFixDocs

Posted on • Originally published at techfixdocs.my.id

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

Error fixing Node.js and npm issues on Ubuntu.

The Problem

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

                    Step 1: Open the terminal and run the command 'sudo apt-get update' to ensure that your package list is up-to-date.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.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

                    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.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.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.
Enter fullscreen mode Exit fullscreen mode

Full step-by-step guide with screenshots: Read the complete fix here

Found this helpful? Check out more verified tech fixes at TechFixDocs

Top comments (0)