【问题标题】:I cannot install any package using npm (need for react-router-dom)我无法使用 npm 安装任何软件包(需要 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 混合使用。选择一个并坚持下去。

标签: node.js reactjs npm npm-install yarnpkg


【解决方案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

【讨论】:

  • 最后一行创建新项目还是更新?
  • 是的,你可以根据需要更改最后一条命令!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-18
  • 1970-01-01
  • 1970-01-01
  • 2017-04-06
  • 2022-11-01
  • 1970-01-01
相关资源
最近更新 更多