bug: Invalid `Podfile` file: cannot load such file '../../node_modules/@capacitor/ios/scripts/pods_helpers'
See original GitHub issueBug 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:
- Created a year ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top GitHub Comments
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.
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; }`