Skip to content

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

Open
@mircopz

Description

@mircopz

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions