【问题标题】:Command `yarn add react-native --exact` failed命令 `yarn add react-native --exact` 失败
【发布时间】:2020-01-09 11:28:50
【问题描述】:

我尝试创建新项目,但发生了这种情况,我更新了核心,正如他们在此处所说的 How to update core-js to core-js@3 dependency? 但也没有什么可以帮助我 我使用的是 windows 10,我该怎么办?

c:\Users\alothman\Desktop>npx react-native init travelApp
This will walk you through creating a new React Native project in c:\Users\alothman\Desktop\travelApp
Using yarn v1.21.1
Installing react-native...
yarn add v1.21.1
info No lockfile found.
[1/4] Resolving packages...
warning react-native > fbjs > core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning react-native > create-react-class > fbjs > core-js@1.2.7: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning react-native > fbjs-scripts > core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning react-native > metro-babel-register > core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
[2/4] Fetching packages...
error An unexpected error occurred: "C:\\Users\\alothman\\AppData\\Local\\Yarn\\Cache\\v6\\npm-@babel-runtime-7.7.7-194769ca8d6d7790ec23605af9ee3e42a0aa79cf-integrity\\node_modules\\@babel\\runtime\\.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 "c:\\Users\\alothman\\Desktop\\travelApp\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
{ Error: Command failed: yarn add react-native --exact
    at checkExecSyncError (child_process.js:629:11)
    at execSync (child_process.js:666:13)
    at run (C:\Users\alothman\AppData\Roaming\npm\node_modules\react-native-cli\index.js:294:5)
    at createProject (C:\Users\alothman\AppData\Roaming\npm\node_modules\react-native-cli\index.js:249:3)
    at init (C:\Users\alothman\AppData\Roaming\npm\node_modules\react-native-cli\index.js:200:5)
    at Object.<anonymous> (C:\Users\alothman\AppData\Roaming\npm\node_modules\react-native-cli\index.js:153:7)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 5380,
  stdout: null,
  stderr: null }
Command `yarn add react-native --exact` failed.

【问题讨论】:

  • 似乎 yarn 在 .yarn-metadata.json 中找到了 NUL 字符(再见 0x00)。您是否使用记事本或其他 Windows 编辑器对此进行了编辑?如果是这样,它可能将其保存为 Unicode 而不是纯 ASCII(有时称为 ANSI)
  • 不,我没有改变任何东西

标签: javascript reactjs react-native yarnpkg


【解决方案1】:

我认为您可能会收到此错误,因为您之前已全局安装了 react-native-cli。因此,首先使用以下命令删除 react-native-cli

npm uninstall -g react-native-cli

现在尝试创建项目:

npx react-native init travelApp

【讨论】:

  • 这也解决了节点引擎过时的问题。感谢您提供有用的信息
【解决方案2】:
npm config set registry "https://registry.npmjs.org"

这对我有用!

【讨论】:

  • 我不知道这如何或为什么解决了我的问题。我刚刚在这个issue看到它
【解决方案3】:

检查您使用的节点版本是否正确 (>= 12.13.0):

node --version

如果您使用的版本不正确,请使用 nvm 安装最新版本并切换到该版本。

https://heynode.com/tutorial/install-nodejs-locally-nvm/

【讨论】:

    【解决方案4】:

    对我来说,问题在于使用的是旧版本的节点。我升级到 node v12,然后再次尝试安装,它成功了。

    nvm install 12

    nvm use 12

    然后

    react-native init Project

    【讨论】:

    • 谢谢。它对我有用!
    【解决方案5】:

    您需要升级节点版本。

    你可以安装>10.0节点。

    【讨论】:

      【解决方案6】:

      尝试将节点版本升级到最新版本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-04-18
        • 2020-10-25
        • 2021-05-10
        • 2022-01-06
        • 2022-12-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多