【问题标题】:npm install --no-optional Missing required argumentnpm install --no-optional 缺少必需的参数
【发布时间】:2020-04-28 15:50:49
【问题描述】:

/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

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

/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

知道这里有什么问题吗?

【问题讨论】:

    标签: node.js npm npm-install


    【解决方案1】:

    你的 npm 版本已经完全过时了。你在 npm v3.5.2 上,而 npm v6.14.4 已经发布了。

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

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

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

    编辑

    如何更新 node.js

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

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

    谢天谢地,它处理了一切,只需点击几下“下一步” 按钮 我在我的 Windows 机器上运行了最新的 Node.js 版本。

    (这里是original answer

    Docker 用户,这里是官方Node.js image


    PS:要检查您的 Node 版本,请使用 npm versionnode --version
    PPS: 请留意 NodeJS blog - Vulnerabilities,以免错过重要的安全版本。

    【讨论】:

    • mhh... 可能是因为您的节点版本也严重过时。顺便提一句。真的有必要使用--no-optional标志吗?
    • @roy 我也编辑了我的答案。请看一看。 (您使用 node v4.2.6 和 v14 可用)
    • 更新到最新节点版本的更好答案:askubuntu.com/a/635469/485874
    • 非常感谢!更好的安装方法是确定版本,通常当我们遵循一些教程时,确实有旧版本。
    猜你喜欢
    • 1970-01-01
    • 2021-11-05
    • 2018-10-28
    • 2018-12-01
    • 2016-06-29
    • 2018-06-20
    • 2020-09-27
    • 1970-01-01
    相关资源
    最近更新 更多