Не удалось установить модуль для проекта React-native с использованием Yarn Berry

Просто я не могу установить модуль для проекта React-native, когда использую пряжу — Berry или любую более новую версию 3.x или 4.x. Есть ли кто-нибудь, кто сделал эту работу? Спасибо!

Это можно повторно ввести, выполнив следующие действия:

1 - вариант набора пряжи ягода

2 - npx реагирует на родную инициализацию abc

Вы получите ошибку при установке файлов pod. То же самое и с существующими проектами. Я использую реагирующую версию 0.74.0, 0.74.1.

 #  from /Users/administrator/Desktop/abc/ios/Podfile:2
 #  -------------------------------------------
 #  # Resolve react_native_pods.rb with node to allow for hoisting
 >  require Pod::Executable.execute_command('node', ['-p',
 #    'require.resolve(
 #  -------------------------------------------
Couldn't install Pods. Updating the Pods project and trying again...
Command `pod install` failed.
└─ Cause: Invalid `Podfile` file: [!] /opt/homebrew/bin/node -p require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  ) /Users/administrator/Desktop/abc/ios

node:internal/modules/cjs/loader:1205
  throw err;
  ^

Error: Cannot find module 'react-native/scripts/react_native_pods.rb'
Require stack:
- /Users/administrator/Desktop/abc/ios/[eval]
    at Module._resolveFilename (node:internal/modules/cjs/loader:1202:15)
    at Function.resolve (node:internal/modules/helpers:199:19)
    at [eval]:1:9
    at runScriptInThisContext (node:internal/vm:209:10)
    at node:internal/process/execution:118:14
    at [eval]-wrapper:6:24
    at runScript (node:internal/process/execution:101:62)
    at evalScript (node:internal/process/execution:136:3)
    at node:internal/main/eval_string:51:3 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/administrator/Desktop/abc/ios/[eval]' ]
}

Node.js v22.0.0

Вот как выглядит мой файл pod:

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'abc' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'abcTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      # :ccache_enabled => true
    )
  end
end

И файл package.json:

{
  "name": "abc",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.74.1"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.74.83",
    "@react-native/eslint-config": "0.74.83",
    "@react-native/metro-config": "0.74.83",
    "@react-native/typescript-config": "0.74.83",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

Спасибо!

Просто я не могу установить модуль для проекта React-native, когда использую пряжу — Berry или любую более новую версию 3.x или 4.x. Есть ли кто-нибудь, кто сделал эту работу? Спасибо!


269
1

Ответ:

Решено

Добавьте файл .yarnrc.yml в корень вашего проекта с содержимым:

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.1.1.cjs

Также добавьте "packageManager": "[email protected]" к своему package.json

Затем удалите node_modules и yarn.lock.

Запустите yarn set version 4.1.1, затем yarn install и после этого попробуйте установить поды.