[Bug]: With an nx.json config, `npx cap sync` hooks (capacitor:sync:before and capacitor:sync:after) are executing from the node_modules instead of the repo root
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 6.1.1 @capacitor/core: 6.1.1 @capacitor/android: 6.1.1 @capacitor/ios: 6.1.1
Installed Dependencies:
@capacitor/android: not installed @capacitor/cli: 6.1.1 @capacitor/core: 6.1.1 @capacitor/ios: 6.1.1
[success] iOS looking great! 👌
Other API Details
npm 9.5.0
node v18.15.0
Platforms Affected
- [X] iOS
- [X] Android
- [ ] Web
Current Behavior
This is a follow up to https://github.com/ionic-team/capacitor/issues/7581 . Sorry for posting again but I could not manage to create a reproduction repo until now and the issue was closed today so I can't reply there. This comment from de-robat gave me a hint that it was coming from the fact that we are using nx in our repo.
As the reproduction repo suggests below, having an nx.json file inside the project will lead the npx cap sync command to execute at the root of each plugin inside the node_modules (once per plugin) starting with capacitor/cli 6.1.0, whereas:
- if you delete
nx.json, it executes only once, at the root of the repo - if you keep
nx.jsonand downgradecapacitor/clito version 6.0.1, it executes only once, at the root of the repo
Expected Behavior
Execute the capacitor:sync:before and capacitor:sync:after hooks only once and at the root of the repo (and not once per plugin inside the node_modules) when using an nx config and when the version of capacitor/cli is 6.1.0 (like it was in previous versions, e.g. 6.0.1)
If this is an intended behaviour, can you provide some documentation for it, or an alternative to prevent it as it is a change in the behaviour of the hooks of the sync command
Project Reproduction
https://github.com/gabides/capacitor-sample-app-sync-issue
Additional Information
the reproduction repo was created:
- with the
create-capacitor-appcommand line - fixing the package.json versions
- adding an nx.json file
- adding an ios project
- adding a
capacitor:sync:afterhook
This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.
hello, any update on this? it s been open for months ...
For what it's worth, we're seeing the exact same in our repository using NX.
It's more prominent after updating to Capacitor 7 as the sync (or run command) will fail on this and stop execute the steps after the hook.