Fixed: NPM install error missing required argument #1

Step by step fixes for npm install error missing required argument #1

Mar 3, 2023 | Read time 7 minutes

πŸ”” Table of contents

Introduction

Recently I tried to fire up a virtual machine with one of my old web applications. So went to the root of the directory and did the npm install command to get the latest packages. Then I was confronted with the following:

npm install error missing required argument #1

A more verbose error looked like the below:

npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! code EMISSINGARG

npm ERR! typeerror Error: Missing required argument #1
npm ERR! typeerror     at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
npm ERR! typeerror     at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
npm ERR! typeerror     at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
npm ERR! typeerror     at /usr/share/npm/lib/install/deps.js:457:7
npm ERR! typeerror     at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror     at /usr/share/npm/lib/fetch-package-metadata.js:37:12
npm ERR! typeerror     at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5)
npm ERR! typeerror     at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7)
npm ERR! typeerror     at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20)
npm ERR! typeerror     at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror     <http://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /home/ubuntu/workspace/Master/npm-debug.log

The error looks like the issue is coming from NPM, but the culprit is from the node version!

To fix the npm install error missing required argument #1 issue, the most common cause is that you node version is not up to date. With previous Node versions, when you do a npm install you will have to provide a <package-name>. For example

npm install <package-name>

However with newer versions of node, including the <package-name> is not required. So just make sure you have a package.json file.

To fix this error, we can following the below steps:

  1. Upgrade to the latest Node and NPM versions
  2. Reinstall with npm install

1. Upgrade NVM, Node and NPM versions

Firstly, check your NPM and node versions:

npm --version
node --version

If we can see that the NPM and Node versions are out of date, we can proceed to the following steps:

Option 1: To go https://nodejs.org/en/ and install the latest LTS version

The easiest option is to go to https://nodejs.org/en - find the latest LTS (Long Term Support) version and upgrade node.

It is recommended to install Node.js LTS (Long-Term Support) versions for several reasons:

  1. Stability: LTS versions of Node.js are designed to be more stable and reliable than other versions. They are rigorously tested and receive regular bug fixes and security updates. This makes them ideal for production environments where stability and reliability are crucial.
  2. Security: LTS versions of Node.js receive regular security updates that address known vulnerabilities. This helps to keep your application secure and reduce the risk of security breaches.
  3. Compatibility: Many third-party libraries and frameworks are designed to work with specific versions of Node.js. By using an LTS version, you can ensure that your application is compatible with the latest versions of these libraries and frameworks.
  4. Long-term support: LTS versions of Node.js receive long-term support from the Node.js community. This means that they will receive bug fixes and security updates for a minimum of 30 months from the time of their release. This provides developers with a stable and reliable platform for building and deploying applications.

Option 2: Use NVM to manage node versions

Now if you dont want to install directly from the website, we can use NVM to manage our node versions.

The benefit of using NVM is that if the latest LTS version that we install does not work, we can pick and choose a different version and test if it works or not!

The steps to get started are as follows:

  1. If you already have NVM, Uninstall nvm and reinstall. (Note: You can also use chocolatey to do the install instead of relying on the .exe!)

If you don’t have NVM, For windows, we can go to the binary and install NVM located here:

https://github.com/coreybutler/nvm-windows/tags

For linux distros we can do the following:

sudo apt install curl 
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.profile
nvm install node 
  1. Uninstall all versions of node with the following command:

nvm uninstall <node version>

  1. Reinstall needed node version:

nvm install <node version>

In our case we want to install the latest LTS version so the command looks like:

nvm install --lts

  1. Use node version just installed:

nvm use <node version>

After we have installed the latest LTS version, the use command can specify as follows:

nvm use --lts

Reinstall with npm install

After you have upgraded node to the latest LTS version, we can clean the project directory and try a fresh install.

  1. Firstly, open up the terminal and go to the root of your project directory

Tip: Try clear NPM cache

We can try running npm cache clear --force to clear the NPM cache. If this does not work - proceed to step 2

  1. We need to delete the /node_modules with the following command (you might need to use sudo before each command):

rm -rf node_modules

  1. Delete package-lock.json file using the rm command:

rm -rf package-lock.json

  1. Install the dependencies using the following command:

npm install

With the new node LTS version, the npm install command should now work!

Summary

In this post, I went over an issue with NPM install error missing required argument #1. The issue is usually caused by an outdated Node version. Previous versions of node requires you to run npm install with a argument such as <package-name>. With newer versions this is not required!

To fix the error, we need to upgrade our Node version to the latest LTS (Long Term Support) version. To do this we can go straight to the node website (https://nodejs.org/en/) or use NVM to manage our node versions.

After we have installed the latest node version, we can clean out the project (removing node_modules and cache) and reinstall with npm install!

πŸ‘‹ About the Author

G'day! I am Huy a software engineer based in Australia. I have been creating design-centered software for the last 10 years both professionally and as a passion.

My aim to share what I have learnt with you! (and to help me remember πŸ˜…)

Follow along on Twitter , GitHub and YouTube