9

/usr/bin/npm" "install" "--no-optional gives me the following error on Ubuntu 16.04 (Xenial Xerus):

npm ERR! Linux 4.4.0-1098-aws
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "--no-optional"
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

I updated npm with /usr/bin/npm install -g npm@latest but now I get

/usr/local/lib/node_modules/npm/bin/npm-cli.js:85
      let notifier = require('update-notifier')({pkg})
      ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

What’s is wrong here?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
roy
  • 6,344
  • 24
  • 92
  • 174

1 Answers1

16

Your npm version is completely outdated. You are on npm v3.5.2, while npm v6.14.4 has already been released.

You need to upgrade npm to use the --no-optional flag. For that see:

docs.npmjs.com: Try the latest stable version of npm

You can upgrade to the latest version of npm using: npm install -g npm@latest

How to update Node.js

This is a simple solution that works for all supported operating systems, including Windows:

After a lot of surfing and not finding a straight solution, I just tried going to Node.js site, clicked the DOWNLOADS button on homepage and executed the installer program (MSI).

Thankfully it took care of everything and with a few clicks of 'Next' button I got the latest Node.js version running on my Windows machine.

(Here is the original answer.)

Download Node.js buttons

For Docker users, here's the official Node.js image.


PS: To check your Node.js version, use npm version or node --version. PPS: Keep an eye on the Node.js blog - Vulnerabilities, so you don't miss important security releases.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Niklas E.
  • 1,848
  • 4
  • 13
  • 25
  • mhh... maybe because your node version is also heavily outdated. Btw. Is it really necessary to use the `--no-optional` flag? – Niklas E. Apr 28 '20 at 16:24
  • @roy I have edited my answer as well. Please have a look. (you using node v4.2.6 and v14 is available) – Niklas E. Apr 28 '20 at 16:33
  • A better answer for updating to latest node version: https://askubuntu.com/a/635469/485874 – fireball.1 Jul 07 '21 at 06:19
  • Thanks so much! The better way to install is to be sure with the versions, usually when we follow some tutorial, there is really old versions. – Geancarlo Murillo Dec 10 '21 at 14:52