Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unknown tag !<!ruby/object:Pathname> when using with react-native-unimodules #805

Closed
oaosman84 opened this issue Oct 17, 2019 · 14 comments · Fixed by #810
Closed

unknown tag !<!ruby/object:Pathname> when using with react-native-unimodules #805

oaosman84 opened this issue Oct 17, 2019 · 14 comments · Fixed by #810

Comments

@oaosman84
Copy link

Environment

System:
    OS: macOS Mojave 10.14.6
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 37.18 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.10.0 - /var/folders/05/dbq77cwj3c5cl2r9c0qkh6h80000gn/T/yarn--1571277638840-0.6997444993602164/node
    Yarn: 1.17.3 - /var/folders/05/dbq77cwj3c5cl2r9c0qkh6h80000gn/T/yarn--1571277638840-0.6997444993602164/yarn
    npm: 6.11.3 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
    Android SDK:
      API Levels: 28, 29
      Build Tools: 27.0.3, 28.0.3, 29.0.0
      System Images: android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5522156
    Xcode: 11.0/11A420a - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.1 => 0.61.1

Description

We use react-native-unimodules, which require us to add a use_unimodules! to our Podfile, and our Podfile.lock then has entries like this:

EXTERNAL SOURCES:
  appcenter:
    :path: "../node_modules/appcenter/ios"
  appcenter-analytics:
    :path: "../node_modules/appcenter-analytics/ios"
  appcenter-crashes:
    :path: "../node_modules/appcenter-crashes/ios"
  BVLinearGradient:
    :path: "../node_modules/react-native-linear-gradient"
  CodePush:
    :path: "../node_modules/react-native-code-push"
  DoubleConversion:
    :podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec"
  EXAppLoaderProvider:
    :path: !ruby/object:Pathname
    path: "../node_modules/expo-app-loader-provider/ios"

Running react-native run-ios then results in an error:

error unknown tag !<!ruby/object:Pathname> at line 452, column 5:
        path: "../node_modules/expo-app- ... 
        ^. Run CLI with --verbose flag for more details.
YAMLException: unknown tag !<!ruby/object:Pathname> at line 452, column 5:
        path: "../node_modules/expo-app- ... 
        ^
    at generateError (/Users/osmanosman/Developer/mobile/node_modules/js-yaml/lib/js-yaml/loader.js:167:10)
    at throwError (/Users/osmanosman/Developer/mobile/node_modules/js-yaml/lib/js-yaml/loader.js:173:9)
    at composeNode (/Users/osmanosman/Developer/mobile/node_modules/js-yaml/lib/js-yaml/loader.js:1428:7)
    at readBlockMapping (/Users/osmanosman/Developer/mobile/node_modules/js-yaml/lib/js-yaml/loader.js:1089:11)
    at composeNode (/Users/osmanosman/Developer/mobile/node_modules/js-yaml/lib/js-yaml/loader.js:1359:12)
    at readBlockMapping (/Users/osmanosman/Developer/mobile/node_modules/js-yaml/lib/js-yaml/loader.js:1089:11)
    at composeNode (/Users/osmanosman/Developer/mobile/node_modules/js-yaml/lib/js-yaml/loader.js:1359:12)
    at readBlockMapping (/Users/osmanosman/Developer/mobile/node_modules/js-yaml/lib/js-yaml/loader.js:1089:11)
    at composeNode (/Users/osmanosman/Developer/mobile/node_modules/js-yaml/lib/js-yaml/loader.js:1359:12)
    at readDocument (/Users/osmanosman/Developer/mobile/node_modules/js-yaml/lib/js-yaml/loader.js:1519:3)

It seems that _warnAboutPodInstall fails on checking Podfile.lock, and the entire command fails. Commenting out that line in runIOS/index.js fixes this.

Reproducible Demo

Hopefully info above is enough, let me know if not. Note that this happens on 3.0.0-alpha* but not on 2.9.0m, which doesn't have that check.

@Maushundb
Copy link
Contributor

Maushundb commented Oct 17, 2019

It seems like this line is the culprit -

return Object.keys(safeLoad(fileContent)['SPEC CHECKSUMS'] || {});

When Podfile.lock isn't a valid YAML file, js-yaml will throw an error on this check. In our case, it thinks :path: !ruby/object:Pathname is referring to a yaml key reference and can't find it, thus marking it as invalid. Seeing how ya'll only use the SPEC CHECKSUMS key for this warning, I would imagine there's a fairly simple workaround.

I do not know if Cocoapods guarantees that Podfile.lock is always a valid YAML file, so this might be a good thing to address for other cases as well.

@Maushundb
Copy link
Contributor

Maushundb commented Oct 17, 2019

Changed that file to

  const CHECKSUM_KEY = 'SPEC CHECKSUMS';
  // Previous portions of the lock file could be invalid yaml.
  // Only parse parts that are valid
  const tail = fileContent.split(CHECKSUM_KEY).slice(1);
  const checksumTail = CHECKSUM_KEY + tail;

  return Object.keys(safeLoad(checksumTail)[CHECKSUM_KEY] || {});

With a test file of

PODS:
  - MyPackage (1.0.0)

EXTERNAL SOURCES:
  ExternalInterface:
    :path: !ruby/object:Pathname
    path: "../node_modules/MyOtherPackage/ios"

SPEC CHECKSUMS:
  MyPackage: 77fd5fb102a4a5eedafa2c2b0245ceb7b7c15e45
  MyOtherPackage: a9bb76128853e98a9ef6d12b0c8c91debc9bc475


PODFILE CHECKSUM: a8110dc7c367fc529b8b6a1084258784444d62ec

COCOAPODS: 1.7.5

Tried to create a PR but looks like I'm getting 403 permission denied when trying to push a branch.

@thymikee
Copy link
Member

@Titozzz @orta can you advise here?
@Maushundb you need to create a fork. See the contributing guide.

@grabbou
Copy link
Member

grabbou commented Oct 17, 2019

@Maushundb, just wanted to say - great investigation here! I appreciate writing this all down including reproductions and some troubleshooting.

@Maushundb
Copy link
Contributor

@Maushundb you need to create a fork. See the contributing guide.

Ah I see, yeah happy to put up a PR if yall think excluding invalid parts of the file is the right way to go about it.

@orta
Copy link
Member

orta commented Oct 17, 2019

Hrm yeah, the ruby yaml parser must be leaking internal state - think @Maushundb has a solid answer above

@enaluz
Copy link

enaluz commented Oct 17, 2019

@Maushundb Thanks for this find! I just ran into this issue while I was trying to upgrade React Native from 0.59.1 to 0.61.2. How can I implement this fix into my project?

@Maushundb
Copy link
Contributor

For now I'd suggest using patch-package to implement the fix to that file (in your repo it'll be babelified, but still readable) until this is fixed and released.

@enaluz
Copy link

enaluz commented Oct 18, 2019

In case this is helpful to anyone else with this same problem, the path for me to fix this issue was
node_modules/@react-native-community/cli-platform-ios/build/link-pods/getDependenciesFromPodfileLock.js (notice it's not Typescript like the file Maushundb referenced in one of the comments above). I simply replaced the final line of the getDependenciesFromPodfileLock() which looks like this:

...
return Object.keys((0, _jsYaml().safeLoad)(fileContent)['SPEC CHECKSUMS'] || {});

with the solution provided above:

...
const { safeLoad } = require("js-yaml");
const CHECKSUM_KEY = 'SPEC CHECKSUMS';
// Previous portions of the lock file could be invalid yaml.
// Only parse parts that are valid
const tail = fileContent.split(CHECKSUM_KEY).slice(1);
const checksumTail = CHECKSUM_KEY + tail;
return Object.keys(safeLoad(checksumTail)[CHECKSUM_KEY] || {});

Not sure if this will work for most people (or anyone else), but thought I should share 😄

@Maushundb
Copy link
Contributor

PR at #810

@martinezguillaume
Copy link

martinezguillaume commented Oct 22, 2019

For a quick fix, you can use :

  "resolutions": {
    "@react-native-community/cli-platform-ios": "2.9.0"
  }

in your package.json to force the version

henrymoulton added a commit to henrymoulton/RN-TS-Unimodules-Starter that referenced this issue Nov 4, 2019
@hzz780
Copy link

hzz780 commented Nov 9, 2019

In case this is helpful to anyone else with this same problem, the path for me to fix this issue was
node_modules/@react-native-community/cli-platform-ios/build/link-pods/getDependenciesFromPodfileLock.js (notice it's not Typescript like the file Maushundb referenced in one of the comments above). I simply replaced the final line of the getDependenciesFromPodfileLock() which looks like this:

...
return Object.keys((0, _jsYaml().safeLoad)(fileContent)['SPEC CHECKSUMS'] || {});

with the solution provided above:

...
const { safeLoad } = require("js-yaml");
const CHECKSUM_KEY = 'SPEC CHECKSUMS';
// Previous portions of the lock file could be invalid yaml.
// Only parse parts that are valid
const tail = fileContent.split(CHECKSUM_KEY).slice(1);
const checksumTail = CHECKSUM_KEY + tail;
return Object.keys(safeLoad(checksumTail)[CHECKSUM_KEY] || {});

Not sure if this will work for most people (or anyone else), but thought I should share 😄

Thanks.
RN 0.61
This one is ok.

@react-native-community/cli-platform-ios 3.0.0-alpha.7 is not ok
I changed this manually. I am waiting the the new package.

@romanonthego
Copy link

I am still experience same issue with version 3.0.0 :(

@Maushundb
Copy link
Contributor

Maushundb commented Nov 19, 2019

Are you sure you're on the right version? If you're using RN, make sure you set your resolutions in package.json so that the CLI version gets resolved correctly:

  "resolutions": {
    "@react-native-community/cli-platform-ios": "3.0.0"
  },

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

Successfully merging a pull request may close this issue.

9 participants