Skip to content

Instantly share code, notes, and snippets.

@5ylvino
Created September 27, 2024 14:31
Show Gist options
  • Save 5ylvino/3ee10652806a402f62a9978137334c23 to your computer and use it in GitHub Desktop.
Save 5ylvino/3ee10652806a402f62a9978137334c23 to your computer and use it in GitHub Desktop.
[!] Invalid `Podfile` file: unexpected token at ''.

SOLUTION - [!] Invalid Podfile file: unexpected token at ''.

Resolution of Incompatibility Error Between React native package.json (even though there is no flexible versioning) version and React native runtime yarn version


Environment versions setup in use
Node v20.10.0
NPM v10.2.3
ruby 3.2.5 App - react native version 0.71.8

1. Issue Overview

The incompatibility error was identified in a react-native-based project, after an updating dev branch to get the latest version of the app based on new UI. The issue occurred as of upgrade on the react-native version for ios cli used by some libraries. that trigger an upgrade on the yarn-use-react-native.

The error occurred as a result of INCOMPATIBILITY OF REACT-NATIVE USED BY YARN DURING RUNTIME WITHOUT FLEXIBLE VERSION IN PLACE. As shown following the log output:

yarn lock change after running install dependencies

react-native@*:
  version "0.75.3" #version used by yarn during yarning
  resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.75.3..."
  integrity sha512-...
  ...

[email protected]:
  version "0.71.8" #version available in package.json without flexible version update (^ or ~)
  resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.71.8..."
  integrity sha512-...
  ...

Error shown after running command on terminal

Configuring Pod with trueally linked Frameworks
error: unknown option '--platform'

[!] Invalid `Podfile` file: unexpected token at ''.

 #  from .../ios/Podfile:18
 #  -------------------------------------------
 #  target 'exmaple-app' do
 >    config = use_native_modules!
 #    $RNFirebaseAsStaticFramework = true
 #  -------------------------------------------

Objective: Resolve the incompatibility issue and ensure the system runs smoothly with pod.


2. Initial Investigation

2.1 Diagnostic Steps:
  1. Checked Node.js Version: Verified the active Node.js, npm, ruby and status of pod file version using the following command:

    node -v && npm -v && ruby -v && ruby -c ios/Podfile
  2. Reviewed package.json: Analyzed the dependencies and identified the version of react/react-native:

    "dependencies": {
    ...
     "react": "18.2.0",
     "react-native": "0.71.8",
     ...
    }
  3. Ran pod install: Attempted to reinstall the packages for pod using:

    cd ios 
    pod install

    Error Output:

    Configuring Pod with trueally linked Frameworks
    error: unknown option '--platform'
    
    [!] Invalid `Podfile` file: unexpected token at ''.
    
    #  from .../ios/Podfile:18
    #  -------------------------------------------
    #  target 'exmaple-app' do
    >    config = use_native_modules!
    #    $RNFirebaseAsStaticFramework = true
    #  -------------------------------------------
    
2.2 Findings:

1). Tracing the cli file that react-native used to read and running pod install './node_modules/@react-native-community/cli-platform-ios/native_modules.rb'
2). Compare the file with that of my colleague
3). Uncover their was slight but significant different occurred.


3. Resolution Process

  • Research on the error via google - github, stackoverflow, chatGPT and relative article
  • upgrading environment setup (phase 1) and test
  • downgrading environment setup (phase 2) and test
  • Tried patch updating on various related files and test
  • Finally, I started tracing project historically based on github from 2 month ago, while checking for any file changes especially on yarn.lock, deleting node_modules and running pod each time until i got the difference point on between branches
  • With the knowledge of knowing the exact time and branch when the error start and before the error and noticing that the branch from last 2 month again do not re-generate yarn.lock, while recent branch does re-generate yarn.lock, so have to check for the differences in yarn lock file based on react-native platform cli running the podile. And below are the outcomes:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
COMMIT MESSAGE ---> initial commit                          | COMMIT MESSAGE ---> switched                              | Uncommitted changes (`git diff`)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                            |                                                            |
react-native@*:                                             | react-native@npm:*                                         | react-native@*:  
  version "0.73.4"                                          |  version "0.73.4"                                          |  version "0.75.3"   
  resolved "..."                                            |  resolved "..."                                            |  resolved "..."  
  integrity ...                                             |  integrity ...                                             |  integrity ... 
  dependencies:                                             |  dependencies:                                             |  dependencies: 
                                                            |                                                            |
[email protected]:                                        | react-native@npm:0.71.8:                                   | [email protected]: 
  version "0.71.8"                                          |  version "0.71.8"                                          |  version "0.71.8"      
  resolved "..."                                            |  resolved "..."                                            |  resolved "..." 
  integrity ...                                             |  integrity ...                                             |  integrity ... 
  dependencies:                                             |  dependencies:                                             |  dependencies: 
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

From table on git diff, the last column shows a change in react-native@* version while the [email protected] version is maintained. Unlike original one the first and second columns.

TABLE DEDUCTION:
1). Hypothetically, due to the fact that on my last PR push was synced to catch up with the merged branch, and after was updating my local dev branch led to the conflicting YARN on end against NPM coming from the update forced upgrade of yarn react-native platform cli.
2). Based on the above and came to conclusions that the issue can only be resolve RUNNING YARN WITHOUT YARN SELF-UPDATE OF REACT-NATIVE PLATFORM CLI.


4. Resolution Outcome

The incompatibility issues were successfully resolved after exploring a way to run yarn install without self-updating on yarn react-native platform cli. Which was accomplished with the following steps:

*** Solution steps ***
1). Edit this package.json and added below on the main object. This forces the runtime react-native not to upgrade during the yarn install

 "resolutions": {
   "react-native": "0.71.8"
 }

2). Remove you node node_modules and cache

  rm -rf ./node_modules
  rm -rf yarn cache clean

3). Re-install fresh dependencies

 yarn

or

 yarn install

4). Because it was causing library to trigger upgrade on the internal react native used in yarn leading to change in cli-platform-ios/native_module.rb content slightly (relative to version). So you run the below command to switch downgrade or force pod libraries to use the relative version that works with react-native resolution value.

 pod update

6. Conclusion

This incompatibility issue highlighted the importance of maintaining consistency in project lock files and relative change implications, on different development machines when collaborating on projects especially. That is possible when there is a change in the run file (yarn to npm) despite the fact that the react-native version value in package.json does not have flexible version ranges.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment