我无法使用 npm 安装任何软件包(需要 react-router-dom)

Posted

技术标签:

【中文标题】我无法使用 npm 安装任何软件包(需要 react-router-dom)【英文标题】:I cannot install any package using npm (need for react-router-dom) 【发布时间】:2021-04-03 10:37:55 【问题描述】:

当我一开始尝试安装某些东西时,我看到一些乱码,而且花费的时间太长,最后它给了我一个错误。最重要的是,纱线没有帮助。

 npm version 6.14.10,  node v14.15.1 ,  yarn v * 1.22.10

我在尝试使用 yarn 安装时看到了这个乱码。

yarn add v1.22.10
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
error An unexpected error occurred: "C:\\Users\\DavrService™\\AppData\\Local\\Yarn\\Cache\\v6\\npm-hoist-non-react-statics-3.3.2-ece0acaf71d62c2969c2ec59feff42a4b1a85b45-integrity\\node_modules\\hoist-non-react-statics\\.yarn-metadata.json: Unexpected token \u0000 in JSON at position 0".
info If you think this is a bug, please open a bug report with the information provided in "D:\\real\\test\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

当我尝试使用 npm 时,它会显示 npm warn deprecated 之类的东西。

【问题讨论】:

你在安装包之前有没有先运行npm init 我认为首先要尝试的是始终删除 node_modules 文件夹并运行 npm inpm i -g 如果您要全局安装软件包。但我认为你的问题需要更多细节。对于任何其他软件包,情况是否有所不同?您是要全局安装还是本地安装? Unexpected token \u0000 in JSON at position 0 表示 JSON 中的第一项是 null。我不建议将yarnnpm 混合使用。选择一个并坚持下去。 【参考方案1】:

运行这些命令(按顺序):

npm cache clear -force

npm uninstall -g create-react-app

npm i -g create-react-app

npm i -g npm

npx create-react-app myapp

【讨论】:

最后一行创建新项目还是更新? 是的,你可以根据需要更改最后一条命令!

以上是关于我无法使用 npm 安装任何软件包(需要 react-router-dom)的主要内容,如果未能解决你的问题,请参考以下文章

无法使用 npm 安装任何东西(反应)

在没有代理的情况下无法使用 npm ECONNRESET 安装任何东西

如何安装小于任何特定版本的npm软件包

VSTS 软件包提要:配置客户端以使用 vsts 提要后无法安装公共 npm 软件包

无法通过 npm 安装 gulp-jshint

NPM 和 Yarn 无法安装任何东西