npm 8.5.5:在@npmcli\树列表中未检测到标记

pnwntuvh  于 2023-03-18  发布在  其他
关注(0)|答案(1)|浏览(296)

在将npm(通过nvm)升级到8.5.5 npm之后,命令不再起作用:
例如,npm --verbose ls webpack失败,原因是:

npm verb stack C:\Users\marti\AppData\Roaming\nvm\v16.15.0\node_modules\npm\node_modules\@npmcli\arborist:1
npm verb stack ../../workspaces/arborist
npm verb stack ^
npm verb stack 
npm verb stack SyntaxError: Unexpected token '.'
npm verb stack     at Object.compileFunction (node:vm:352:18)
npm verb stack     at wrapSafe (node:internal/modules/cjs/loader:1033:15)
npm verb stack     at Module._compile (node:internal/modules/cjs/loader:1069:27)
npm verb stack     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
npm verb stack     at Module.load (node:internal/modules/cjs/loader:981:32)
npm verb stack     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm verb stack     at Module.require (node:internal/modules/cjs/loader:1005:19)
npm verb stack     at require (node:internal/modules/cjs/helpers:102:18)
npm verb stack     at Object.<anonymous> (C:\Users\marti\AppData\Roaming\nvm\v16.15.0\node_modules\npm\lib\commands\ls.js:7:18)
npm verb stack     at Module._compile (node:internal/modules/cjs/loader:1105:14)
npm verb cwd D:\dev\xxx
npm verb Windows_NT 10.0.19043
npm verb argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "--verbose" "ls" "webpack"
npm verb node v16.15.0
npm verb npm  v8.5.5
npm ERR! Unexpected token '.'

注意:当我使用nvm并切换回节点16. 12(npm版本8. 1. 0)时,它工作正常

详情

错误引用的文件
C:\Users\xxx\AppData\Roaming\nvm\v16.15.0\node_modules\npm\node_modules\@npmcli\arborist只包含这个(我猜这是无效的js):

../../workspaces/arborist

我尝试过的(但不起作用的)

  • 重新启动我的电脑
  • 通过nvm卸载节点16.15并重新安装

变通方案

  • 删除文件C:\Users\xxx\AppData\Roaming\nvm\v16.15.0\node_modules\npm\node_modules\@npmcli\arborist
  • 然后将aborist目录从较旧的节点版本复制到该目录:例如从C:\Users\xxx\AppData\Roaming\nvm\v16.12.0\node_modules\npm\node_modules\@npmcli\arborist\

知道我做错了什么吗?或者这只是npm 8.5.5中的一个bug

yzxexxkh

yzxexxkh1#

这对我很有效:

  • 已将nvm更新为版本1.1.9(旧安装版本为1.1.7
  • 然后重新安装节点版本16.15.0(现在aborist是一个目录),命令按预期工作

相关问题