apache / apache/cordova-common

Failed to install '<plugin>': TypeError: Cannot read properties of undefined (reading 'id')

Open
#201 8 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
42
Forks
45
Avg merge
5h 41m
Merged PRs (30d)
6

Description

# Bug Report

## Problem
I have created an internal cordova plugin at our company which adds the android:networkSecurityConfig attribute to the /manifest/application/ tag in AndroidManifest.xml via the following `

```

This works flawlessly if the plugin is added the first time. But if the plugin is removed and then re-added again an error occurrs.

### What is expected to happen?
The plugin should be added again without any issues.

### What does actually happen?
If the plugin is re-added, the following error is produced:
```
Failed to install 'uq-cordova-plugin-settings': TypeError: Cannot read properties of undefined (reading 'id')
at registerConflict (D:\CordovaApp\node_modules\cordova-common\src\ConfigChanges\ConfigChanges.js:255:43)
at D:\CordovaApp\node_modules\cordova-common\src\ConfigChanges\ConfigChanges.js:283:34
at Array.forEach ()
at PlatformMunger._is_conflicting (D:\CordovaApp\node_modules\cordova-common\src\ConfigChanges\ConfigChanges.js:259:21)
at PlatformMunger.add_plugin_changes (D:\CordovaApp\node_modules\cordova-common\src\ConfigChanges\ConfigChanges.js:106:59)
at D:\CordovaApp\node_modules\cordova-common\src\PluginManager.js:120:33
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Cannot read properties of undefined (reading 'id')
```

## Information
The problem is that, upon removal, the `platforms/android/android.json` looks like the following:
```
"AndroidManifest.xml": {
"parents": {
"/*": [
{
"xml": "",
"count": 1
},
{
"xml": "",
"count": 1
},
...
],
"application": [],
"/manifest/application": []
}
}
```
Notice the empty array for `/manifest/application`.

The code in `ConfigChanges.js` `registerConflict` accesses the first entry in the array, which does not exist in this case. Therefore, the above error is being thrown.
![image](https://github.com/apache/cordova-common/assets/12544460/1a72aaca-c3f1-45e4-814f-4afbd8dc48bc)

With a slight adjustment to the code the above error could be avoided, but it leads to another error ("There was a conflict trying to modify attributes with") which is a different issue, I guess.
![image](https://github.com/apache/cordova-common/assets/12544460/d6ca3d2f-0d15-4333-b7c9-36c98984e583)

### Command or Code
Create a new cordova project, create a new plugin directory with the ` produces the error
```

A minimum viable plugin.xml looks like this:
```

Test
Cordova Device Test
Apache 2.0
cordova,test





```
The package.json looks like this:
```
{
"name": "cordova-plugin-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
```

### Environment, Platform, Device
Environment: Windows 10 with PowerShell

### Version information
Cordova-Cli: 12.0.0 (cordova-lib@12.0.1)
Cordova Platform Android: 12.0.0
Windows 10
PowerShell 7

## Checklist

- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above

Contributor guide

Open the contributing guide

Research direction

Start in src/ConfigChanges/ConfigChanges.js at registerConflict and _is_conflicting, then reproduce the issue with the listed Cordova create, platform add, plugin add, remove, and re-add commands. Inspect the resulting platforms/android/android.json, especially the empty /manifest/application array; done means the plugin can be removed and re-added without the undefined id error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
mobile-dev, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.