npm install --no-optional 缺少必需的参数

roy*_*roy 9 node.js npm npm-install

/usr/bin/npm" "install" "--no-optional 在 ubuntu 16.04 上给我以下错误

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
Run Code Online (Sandbox Code Playgroud)

我更新了npm/usr/bin/npm install -g npm@latest但现在我得到了

/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
Run Code Online (Sandbox Code Playgroud)

知道这里有什么问题吗?

Nik*_* E. 13

你的 npm 版本已经完全过时了。您使用的是 npm v3.5.2,而 npm v6.14.4 已经发布。

您需要升级 npm 才能使用该--no-optional标志。为此,请参阅:

docs.npmjs.com:尝试最新的稳定版 npm

您可以使用以下命令升级到最新版本的 npm: npm install -g npm@latest

编辑

如何更新 node.js

这是一个简单的解决方案,适用于所有受支持的操作系统,包括Windows

经过大量冲浪并没有找到直接的解决方案后,我只是尝试转到Node.js站点,单击主页上DOWNLOADS按钮并执行安装程序 (MSI)。

值得庆幸的是,它处理了所有事情,只需点击几下“下一步”按钮,我就可以在我的 Windows 机器上运行最新的 Node.js 版本。

(这是原始答案

下载 NodeJS 按钮

对于Docker用户,这里是官方的Node.js 镜像


PS:要检查您的 Node 版本,请使用npm versionnode --version.
PPS:密切关注NodeJS 博客 - 漏洞,这样您就不会错过重要的安全版本。