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

Capacitor: Node modules removed after sync and open commands #1152

Open
mircopz opened this issue Nov 5, 2024 · 1 comment
Open

Capacitor: Node modules removed after sync and open commands #1152

mircopz opened this issue Nov 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mircopz
Copy link

mircopz commented Nov 5, 2024

Describe the bug
This issue was already open in previous repository nxext/nx-extensions-ionic#6, I'm writing it here again for completeness. The bug is quite fixed, but in additional context section below I suggest how to improve this behavior.

When the nx run app-name:sync:android command is run, npm install is executed at the beginning, so it generates a node_modules folder in the application folder. Next, capacitor generates the capacitor.settings.gradle file in the Android project, which references the various capacitor packages in the application based on the node_modules folder in the application. Once the capacitor synchronisation command has been completed, nxext deletes the node_modules folder. This means that the relative paths in the capacitor.settings.gradle file refer to content which does not exist.

To Reproduce
At the root of your project, run :

  • nx run app-name:sync:android
  • nx run app-name:open:android
  • In Android Studio, try to build your application, you will get this type of error :
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve project :capacitor-android.
     Required by:
         project :app
      > No matching configuration of project :capacitor-android was found. The consumer was configured to find a component for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.0.0' but:
          - None of the consumable configurations have attributes.

If you look to the file capacitor.settings.gradle, you will have this :

include ':capacitor-android'
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')

Expected behavior
The file capacitor.settings.gradle must refers paths to the node_modules folder of the root, like this :

include ':capacitor-android'
project(':capacitor-android').projectDir = new File('../../../node_modules/@capacitor/android/capacitor')

Additional context
I found the option --preserveProjectNodeModules=true which preserves the node_modules folder, but in my opinion it's no good having to add a parameter for the whole process to work. This option should be applied to the command nx run app-name:sync:android as well as nx run app-name:open:android, because on the open command, an npm install is also executed as well as the deletion of the node_modules folder.

You think this could become the default behavior? This way we don't have to set the flag preserveProjectNodeModules again for every new project created.

@mircopz mircopz added the bug Something isn't working label Nov 5, 2024
@pawel-twardziak
Copy link
Contributor

Hi @mircopz thanks for reporting this issue and your suggestions. Great input. Will check on it. FIY @edbzn @DominikPieper - any thoughts about it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants