命令“Yarn添加React-本机-精确”失败

0qx6xfy6  于 2023-03-19  发布在  React
关注(0)|答案(8)|浏览(165)

我试图创建新的项目,但这种情况发生,我更新的核心,因为他们在这里说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.
n3h0vuf2

n3h0vuf21#

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

npm uninstall -g react-native-cli

现在尝试创建项目:

npx react-native init travelApp
e4eetjau

e4eetjau2#

npm config set registry "https://registry.npmjs.org"

这对我很有效!

m0rkklqb

m0rkklqb3#

检查您使用的节点版本是否正确(〉= 12.13.0):
node --version
如果您使用的版本不正确,请使用nvm安装最新版本,然后切换到该版本。
https://heynode.com/tutorial/install-nodejs-locally-nvm/

dvtswwa3

dvtswwa34#

对我来说,问题是使用了旧版本的Node。我升级到Node V12,然后再次尝试安装,结果成功了。
nvm install 12
nvm use 12
然后
react-native init Project

zwghvu4y

zwghvu4y5#

您需要升级节点版本。
您可以安装〉10.0节点。

mm9b1k5b

mm9b1k5b6#

如果您已在系统上安装了Node,请确保它是Node 14或更新版本。

vfh0ocws

vfh0ocws7#

您可以使用此命令解决此问题

npx react-native@latest init YourProjectName
mklgxw1f

mklgxw1f8#

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

相关问题