在 nodejs 中安装 express 时出现 npm 错误

npm error while installing express in nodejs

我在 npm install express 时遇到问题。在 '..."dist":{"shasum":"e84' 附近解析时 JSON 输入意外结束,这是我遇到的错误。

>  0 info it worked if it ends with ok
>         1 verbose cli [ 'D:\Program Files\nodejs\node.exe',
>         1 verbose cli   'C:\Users\Rakshith Rakshak\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js',
>         1 verbose cli   'install',
>         1 verbose cli   '-g',
>         1 verbose cli   'express' ]
>         2 info using npm@6.9.2
>         3 info using node@v10.15.3
>         4 verbose npm-session 203510227a9454ec
>         5 silly install loadCurrentTree
>         6 silly install readGlobalPackageData
>         7 http fetch GET 304 https://registry.npmjs.org/express 346ms (from cache)
>         8 silly fetchPackageMetaData error for express@latest Unexpected end of JSON input while parsing near
> '..."dist":{"shasum":"e84'
>         9 timing stage:rollbackFailedOptional Completed in 1ms
>         10 timing stage:runTopLevelLifecycles Completed in 417ms
>         11 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '..."dist":{"shasum":"e84'
>         11 verbose stack     at JSON.parse (<anonymous>)
>         11 verbose stack     at parseJson (C:\Users\Rakshith Rakshak\AppData\Roaming\npm\node_modules\npm\node_modules\json-parse-better-errors\index.js:7:17)
>         11 verbose stack     at consumeBody.call.then.buffer (C:\Users\Rakshith
> Rakshak\AppData\Roaming\npm\node_modules\npm\node_modules\node-fetch-npm\src\body.js:96:50)
>         11 verbose stack     at process._tickCallback (internal/process/next_tick.js:68:7)
>         12 verbose cwd D:\My Files\node\role-based-auth
>         13 verbose Windows_NT 10.0.18362
>         14 verbose argv "D:\Program Files\nodejs\node.exe" "C:\Users\Rakshith
> Rakshak\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js"
> "install" "-g" "express"
>         15 verbose node v10.15.3
>         16 verbose npm  v6.9.2
>         17 error Unexpected end of JSON input while parsing near '..."dist":{"shasum":"e84'
>         18 verbose exit [ 1, true ]

清除 NPM 缓存并再次尝试安装 'Express'。 运行 命令下方

npm cache clean --force

然后安装 express

  npm install express