Skip to content

[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 #7606

Open
@gabides

Description

@gabides

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

  • iOS
  • Android
  • Web

Current Behavior

This is a follow up to #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.json and downgrade capacitor/cli to 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-app command line
  • fixing the package.json versions
  • adding an nx.json file
  • adding an ios project
  • adding a capacitor:sync:after hook

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions