无效的 Podfile 文件意外模板 EOS

use*_*339 10 cocoapods react-native

我已经与这个错误作斗争好几天了,试图开始一份新工作。尝试在 React Native cli 项目上运行 pod install 时遇到问题,我已经尝试了这里所有可能的解决方案,但不适用于我的。

错误:

[!] Invalid `Podfile` file: /Users/decagon/kumoafrica/node_modules/react-native/scripts/react_native_pods_utils/script_phases.rb:39: syntax error, unexpected <<
    template =<<~EOS
                ^
/Users/decagon/kumoafrica/node_modules/react-native/scripts/react_native_pods_utils/script_phases.rb:40: unknown regexp options - ll
/Users/decagon/kumoafrica/node_modules/react-native/scripts/react_native_pods_utils/script_phases.rb:41: dynamic constant assignment
        RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd)
                                         ^
/Users/decagon/kumoafrica/node_modules/react-native/scripts/react_native_pods_utils/script_phases.rb:41: `$(' is not allowed as a global variable name
/Users/decagon/kumoafrica/node_modules/react-native/scripts/react_native_pods_utils/script_phases.rb:41: syntax error, unexpected end-of-input
        RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd)
                                          ^.

 #  from /Users/decagon/kumoafrica/ios/Podfile:1
 #  -------------------------------------------
 >  require_relative '../node_modules/react-native/scripts/react_native_pods'
 #  require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
 #  -------------------------------------------
Run Code Online (Sandbox Code Playgroud)

pod 文件:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11.0'
install! 'cocoapods', :deterministic_uuids => false

target 'kumo' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

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

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end
Run Code Online (Sandbox Code Playgroud)

包.json:

{
  "name": "kumo",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
  },
  "dependencies": {
    "react": "17.0.2",
    "react-native": "0.68.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "@types/jest": "^26.0.23",
    "@types/react-native": "^0.67.3",
    "@types/react-test-renderer": "^17.0.1",
    "@typescript-eslint/eslint-plugin": "^5.17.0",
    "@typescript-eslint/parser": "^5.17.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.67.0",
    "react-test-renderer": "17.0.2",
    "typescript": "^4.4.4"
  },
  "resolutions": {
    "@types/react": "^17"
  },
  "jest": {
    "preset": "react-native",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

如果还有什么需要询问,请帮忙。

小智 14

不知道现在这是否有帮助,但如果您在 M1 芯片机器上从头开始运行 React Native,我可以通过执行以下操作来解决此问题:

cd ios
bundle install
bundle exec pod install
Run Code Online (Sandbox Code Playgroud)

pod install经过几个小时的奋斗,这就是我真正找到工作的方式。

可以在此处找到相同的示例: https: //reactnative.dev/docs/environment-setup在“创建新应用程序”部分下。


小智 5

我认为您是 Mac M1 用户,因此请按照以下步骤操作:

  1. 卸载本地cocoapods gem

    sudo gem uninstall cocoapods
    
    Run Code Online (Sandbox Code Playgroud)
  2. 安装自制程序

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
    Run Code Online (Sandbox Code Playgroud)

    访问网站

  3. 最后通过Homebrew安装cocoapods

    brew install cocoapods
    
    Run Code Online (Sandbox Code Playgroud)

它会起作用,否则检查这个