question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Invalid `Podfile` file: cannot load such file '../../node_modules/@capacitor/ios/scripts/pods_helpers'

See original GitHub issue

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 4.1.0
  @capacitor/core: 4.1.0
  @capacitor/android: 4.1.0
  @capacitor/ios: 4.1.0

Installed Dependencies:

  @capacitor/cli: 4.1.0
  @capacitor/core: 4.1.0
  @capacitor/android: 4.1.0
  @capacitor/ios: 4.1.0

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

ios

Current Behavior

When running npx cap sync, I get the following error

[!] Invalid `Podfile` file: cannot load such file --
/Users/marco/Documents/frontend/apps/code/node_modules/@capacitor/ios/scripts/pods_helpers.

#  from /Users/marco/Documents/frontend/apps/code/ios/App/Podfile:1
#  -------------------------------------------
>  require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'
#
#  -------------------------------------------
        

The ‘pods_helper’ path doesn’t get resolved to the right path, because of the monorepo the module is four directories up instead of two.

All the other paths are getting resolved to '../../../../node_modules/@capacitor/ios'.

Expected Behavior

The CLI should resolve the ‘@capacitor/ios’ module and replace the path. For example in my case it would be: require_relative '../../../../node_modules/@capacitor/ios/scripts/pods_helpers' After I changed the path, everything worked fine.

Code Reproduction

I created a yarn monorepo with workspaces: https://github.com/Marcoru97/capacitor-cli-demo

Affected file: https://github.com/Marcoru97/capacitor-cli-demo/blob/main/apps/capacitor-test/ios/App/Podfile

Run npx cap sync to get the error

Other Technical Details

npm --version output: 8.1.0

node --version output: v16.13.0

pod --version output (iOS issues only): 1.11.2

Additional Context

I saw that you are already resolving the package via ‘require.resolve’ but only replaced it in the pods list: https://github.com/ionic-team/capacitor/blob/17fbabb2a77d1b356d24048efc5883bd4d049104/cli/src/ios/update.ts#L141

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
jcesarmobilecommented, Sep 15, 2022

The path is hardcoded in the template, didn’t have mono repos into account. As workaround you can manually change the path because it’s not being written by Capacitor CLI, so if you change it, it won’t be overwritten. We will need to use a regular expression to replace the hardcoded value with the actual value.

0reactions
fedorenko-dmitriycommented, Nov 28, 2022

I wrote the script which changes deps automatically, pls check it and add it into update.js, this helps many people who can not understand why their project doesn’t work

`const { rootDir } = require(‘…/…/…/rootDir.js’);

const lengthRootDir = rootDir.split(‘/’).length; const lengthCurrentDir = __dirname.split(‘/’).length; const relativeDiffLength = lengthCurrentDir - lengthRootDir;

const relativePrefix = getRelativePrefix(relativeDiffLength);

let podFileContent = utils_fs_1.readFileSync(podFilePath, { encoding: ‘utf-8’ }); podFileContent = podFileContent.replace(/require_relative '(…/)+/g, “require_relative '”); podFileContent = podFileContent.replace(‘node_modules/@capacitor/ios/scripts/pods_helpers’, ${relativePrefix}node_modules/@capacitor/ios/scripts/pods_helpers); utils_fs_1.writeFileSync(podFilePath, podFileContent, { encoding: ‘utf-8’ });

function getRelativePrefix(relativeDiffLength) { let relativePrefix = ‘’; let count = 0 while(count <= relativeDiffLength) { count++ relativePrefix = relativePrefix + ‘…/’ }

return relativePrefix; }`

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ask Question - Stack Overflow
I ran npm audit fix and it added react_native_pods file and pod install then worked.
Read more >
EAS Error: Invalid `Podfile` file: cannot load such file -- /Users ...
1 (peer dependency). eas build crashes during the Install pods step with the following error message: Installing pods [!] Invalid `Podfile` file: ...
Read more >
[!] Invalid `Podfile` file: cannot load such file -- /Users/apps ...
Somebody already faced this on 'pod install'? I am trying to install mobile-previewer. [!] Invalid Podfile file: cannot load such file ...
Read more >
pod setup fails with "cannot load such file - Google Groups
Cocoapods is a dependency I need for Flutter. Previous installations were a breeze but after upgrading Ruby to 3.1.0 `pod install` fails ...
Read more >
Cocpods error - Builds - Bitrise Discussions
Bitrise Build Issue Report template im getting [!] Invalid Podfile file: cannot load such file ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found