npm 错误!无效的选项参数

Posted

技术标签:

【中文标题】npm 错误!无效的选项参数【英文标题】:npm ERR! invalid options argument 【发布时间】:2022-01-12 18:20:14 【问题描述】:

软件规格

Software OS npm npx node
Version Windows 10 v8.1.2 v8.1.2 v16.13.1

我正在关注this video,当我尝试使用以下命令在我的系统上创建一个反应应用程序时

npx create-react-app demo

它显示以下错误:

npm ERR! invalid options argument

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\hp\AppData\Local\npm-cache\_logs\2021-12-07T16_44_17_434Z-debug.log

日志文件内容

0 verbose cli [
0 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
0 verbose cli   'C:\\Users\\hp\\AppData\\Roaming\\nvm\\v11.0.0\\node_modules\\npm\\bin\\npm-cli.js',
0 verbose cli   'exec',
0 verbose cli   '--',
0 verbose cli   'create-react-app',
0 verbose cli   'demo'
0 verbose cli ]
1 info using npm@8.1.2
2 info using node@v16.13.1
3 timing npm:load:whichnode Completed in 1ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\npmrc Completed in 2ms
6 timing config:load:builtin Completed in 3ms
7 timing config:load:cli Completed in 2ms
8 timing config:load:env Completed in 1ms
9 timing config:load:file:C:\Users\hp\OneDrive\Desktop\.npmrc Completed in 1ms
10 timing config:load:project Completed in 2ms
11 timing config:load:file:C:\Users\hp\.npmrc Completed in 1ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:C:\Users\hp\AppData\Roaming\npm\etc\npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:credentials Completed in 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 13ms
19 timing npm:load:configload Completed in 13ms
20 timing npm:load:setTitle Completed in 0ms
21 timing npm:load:setupLog Completed in 1ms
22 timing config:load:flatten Completed in 4ms
23 timing npm:load:cleanupLog Completed in 2ms
24 timing npm:load:configScope Completed in 0ms
25 timing npm:load:projectScope Completed in 1ms
26 timing npm:load Completed in 22ms
27 verbose stack TypeError: invalid options argument
27 verbose stack     at optsArg (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\mkdirp\lib\opts-arg.js:13:11)
27 verbose stack     at mkdirp (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\mkdirp\index.js:11:10)
27 verbose stack     at tryCatcher (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
27 verbose stack     at ret (eval at makeNodePromisifiedEval (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\bluebird\js\release\promisify.js:184:12), <anonymous>:13:39)
27 verbose stack     at Object.mkdirfix (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\node_modules\cacache\lib\util\fix-owner.js:36:10)
27 verbose stack     at makeTmp (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\node_modules\cacache\lib\content\write.js:121:19)
27 verbose stack     at write (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\node_modules\cacache\lib\content\write.js:35:19)
27 verbose stack     at putData (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\node_modules\cacache\put.js:11:10)
27 verbose stack     at Object.x.put (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\node_modules\cacache\locales\en.js:28:37)
27 verbose stack     at WriteStream._flush (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\node_modules\make-fetch-happen\cache.js:156:21)
27 verbose stack     at WriteStream._write (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\flush-write-stream\index.js:36:35)
27 verbose stack     at doWrite (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\readable-stream\lib\_stream_writable.js:409:139)
27 verbose stack     at writeOrBuffer (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\readable-stream\lib\_stream_writable.js:398:5)
27 verbose stack     at WriteStream.Writable.write (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\readable-stream\lib\_stream_writable.js:307:11)
27 verbose stack     at WriteStream.end (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\flush-write-stream\index.js:45:41)
27 verbose stack     at WriteStream.end (C:\Users\hp\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\flush-write-stream\index.js:42:47)
28 verbose cwd C:\Users\hp\OneDrive\Desktop
29 verbose Windows_NT 10.0.18363
30 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\hp\\AppData\\Roaming\\nvm\\v11.0.0\\node_modules\\npm\\bin\\npm-cli.js" "exec" "--" "create-react-app" "demo"
31 verbose node v16.13.1
32 verbose npm  v8.1.2
33 error invalid options argument
34 verbose exit 1

也试过运行

npm i create-react-app -g demo

这导致了与上面相同的错误

尝试克隆和运行

我还尝试克隆一个已经在工作的 react 应用程序,当我运行以下命令来安装依赖项时

npm i

这给出了以下错误:

npm ERR! invalid options argument

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\hp\AppData\Local\npm-cache\_logs\2021-12-07T17_12_17_513Z-debug.log

尝试使用npm cache clean --force 清除缓存时出现以下错误:

npm WARN using --force Recommended protections disabled.

有人可以帮我了解哪里出了问题吗?我是否没有正确完成某些安装或错过了任何安装步骤?我可以做些什么来开始在我的机器上创建一个 React 应用程序?任何形式的帮助表示赞赏。如果您需要更多信息,请在 cmets 中告诉我。谢谢!

【问题讨论】:

您是否尝试过像 this 这样完全删除 npm 和节点?好像是安装错误。还尝试按照here 的指示清理 npm 缓存。 我无法清除缓存。也尝试以管理员身份运行该命令,它给出了与我现在包含在我的问题中的相同的错误。 重新安装没有解决问题吗?此外,缓存清理命令似乎只给出了警告而不是错误,因此它可能已成功运行。尝试再次创建 React 应用程序?如果一切都失败了,我想你可以尝试旧版本的 node 和 npm 【参考方案1】:

问题似乎是安装不当。解决此问题的最佳方法是确保正确卸载nodenpm。请按照提到的步骤here。 正确卸载后,前往install node 并继续重新安装。

【讨论】:

【参考方案2】:

我也遇到过类似的问题,但是使用的是arch linux操作系统,这和你是否安装好没有太大关系,有时由于兼容性问题,某些模块会相互干扰。 在我跟踪错误的情况下,错误在 /usr/lib/node_modules/npm/node_modules/* 中。虽然我卸载并重新安装了 nodejs 和 npm 并没有解决,所以我决定在卸载 node 后完全删除 node_modules 文件夹,然后重新安装。 在您使用 Windows 的情况下,该错误会将您发送到文件夹 C:\UsersAppData\Roaming\nvm*。所以我建议你卸载nodejs并完全删除nvm文件夹,因为它是导致错误的那个。

【讨论】:

以上是关于npm 错误!无效的选项参数的主要内容,如果未能解决你的问题,请参考以下文章

当我尝试将任务计划程序中的信息导出到 csv 文件时出现错误:无效的参数/选项 - '>'

npm 安装失败,npm 错误!无效的 json 响应

npm 安装错误 - 无效的 package.json

“npm install”给出错误消息“无效”,它是啥?

Laravel 项目中的“npm run hot”抛出无效配置错误

npm run build 失败并显示“错误:自定义关键字定义无效:data.errors 应该是布尔值”