简体   繁体   中英

Command `yarn add react-native --exact` failed

I tryed to create new project but this happen, I update the core as they said here How to update core-js to core-js@3 dependency? but also no thing help me I use windows 10, what should I do?

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.

I think you might be getting this errors because you have previously installed react-native-cli globally. So, first remove react-native-cli using following command:

npm uninstall -g react-native-cli

Now try creating project:

npx react-native init travelApp
npm config set registry "https://registry.npmjs.org"

这对我有用!

You need to upgrade the node version.

You can install >10.0 node.

在 Windows 上试试这个命令:

choco install -y nodejs.install openjdk8

Check that you are using the correct node version ( >= 12.13.0 ):

node --version

If you are not using the correct version, install the latest using nvm and switch to that version.

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

For me, the issue was using an older version of node. I upgraded to node v12, then tried installing again, and it worked.

nvm install 12

nvm use 12

and then

react-native init Project

If you have already installed Node on your system, make sure it is Node 14 or newer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM