ath0mas opened a new issue #868:
URL: https://github.com/apache/cordova-lib/issues/868
# Bug Report
## Problem
### What is expected to happen?
For a cordova project created through **cordova-lib** node api, with
**npm@7**,
**we expect the npm packages required by each cordova step/command to be
stored and cumulated in _/node_modules/_**
like what's done using npm@6 or with cordova-cli itself with npm@6 and npm@7.
### What does actually happen?
Project creation has correct _/node_modules/_ and runs fine for
- **cordova-lib with npm@6 only** 😢
- cordova-cli with npm@6 and npm@7 👍
In those 3 cases, the order to add plugins and platform does not matter:
plugins first and platform after them, or the opposite, platform first and then
plugins.
😢 Using **cordova-lib with npm@7** results in incomplete _/node_modules/_
and so possibly failing project creation (like when a plugin _after_prepare_
hook script called during `cordova platform add` does not find one of its own
dependencies).
## Information
<!-- Include all relevant information that might help understand and
reproduce the problem -->
Again only since Npm 7, each step is fetching its packages correctly inside
_/node_modules/_ but it is also like wiping its content first.
Each call to `await cordova.plugin('add', pluginName);` or `await
cordova.platform('add', platformName);` will result in its content to have only
_new_ deps for current specific plugin or platform.
* add first plugin: its deps are in _/node_modules/_
* add second plugin: its deps are in _/node_modules/_ but not those of first
plugin **(should be, like with cli and npm 6)**
* add platform: its deps are in _/node_modules/_ but not those of the two
plugins **(should be, like with cli and npm 6)**
* each plugin is now installed for this platform, also calling the
_after_prepare_ hook script if present
* ERROR here if script logically uses one of its own dependencies
### Command or Code
<!-- What command or code is needed to reproduce the problem? -->
_(simplified version of my code ; I am working on a basic and easily
reusable project to share here soon)_
```
await cordova.plugin('add', 'cordova-plugin-device');
await cordova.plugin('add', 'cordova-plugin-androidx-adapter');
await cordova.platform('add', 'android');
```
will give such failure
```
.. // "cordova-plugin-device" added first and ok
.. // "cordova-plugin-androidx-adapter" added second and ok
...
.. // starting _plaftom add_ for "android"
Installing "cordova-plugin-androidx-adapter" for android
Installing "cordova-plugin-device" for android
cordova-plugin-androidx-adapter: EXCEPTION: Failed to load dependencies:
Error: Cannot find module 'recursive-readdir'
Require stack:
- C:\cdv-lib\helloCdvLib\plugins\cordova-plugin-androidx-adapter\apply.js
- C:\cdv-lib\node_modules\cordova-lib\src\hooks\HooksRunner.js
- C:\cdv-lib\node_modules\cordova-lib\src\plugman\install.js
- C:\cdv-lib\node_modules\cordova-lib\src\plugman\plugman.js
- C:\cdv-lib\node_modules\cordova-lib\cordova-lib.js
- C:\cdv-lib\node_modules\cordova\cordova.js
- C:\cdv-lib\generateHelloCdvLib.js
```
### Environment, Platform, Device
<!-- In what environment, on what platform or on which device are you
experiencing the issue? -->
### Version information
<!--
What are relevant versions you are using?
For example:
Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins
Other Frameworks: Ionic Framework and CLI version
Operating System, Android Studio, Xcode etc.
-->
* OS: Windows 10
* Node: 16.0.0 / 14.6.1
* npm: 7.10.0 / 6.14.12
* Cordova:
* CLI 10.0.0
* Lib 10.0.0
* Common 4.0.2
* Fetch 3.0.1
* Cordova Plugins:
*
[cordova-plugin-device](https://www.npmjs.com/package/cordova-plugin-device)
*
[cordova-plugin-androidx-adapter](https://www.npmjs.com/package/cordova-plugin-androidx-adapter)
## Checklist
<!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
- [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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]