cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Matchneer (JIRA)" <>
Subject [jira] [Commented] (CB-13540) cordova-fetch npm install --production clobbers node_modules, causes workflow issues
Date Thu, 09 Nov 2017 17:00:07 GMT


Alex Matchneer commented on CB-13540:

OK, getting closer: we use `yarn` (npm alternative that is generally faster and more reliable)
to install dependencies. I guess we can use npm if we must, but the rest of our tooling is
yarn-based and we figured we'd use it for cordova too.

I still haven't pinpointed the exact issue, but I can reproduce it now:

1. rm -rf node_modules
2. yarn install
3. cordova add platform android --verbose

cordova :: cordova platform add android --verbose
No scripts found for hook "before_platform_add".
No version supplied. Retrieving version from config.xml...
Grabbing pinned version.
Using cordova-fetch for cordova-android@~6.3.0
Running command: npm install cordova-android@~6.3.0 --production --save
Command finished with error code 0: npm install,cordova-android@~6.3.0,--production,--save
Error: Failed to fetch platform cordova-android@~6.3.0
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Failed to get absolute path to installed module

The npm install that internally happens is restructuring the contents of node modules from
what yarn installed; in particular, yarn tries to install modules at the top level, including
devDependency modules, and I believe the --production flag passed to npm install is causing
a bunch of those modules to be deleted in the middle of script execution. Here is a diff on
my node_modules directory before and after the first `cordova platform add android`:

So, I guess the easiest answer is "just use npm and don't try and be clever with yarn", but
it seems non-ideal for Cordova to restructure `node_modules` mid-execution, and it makes the
integration with other workflows a bit more brittle.

I'm gonna continue poking around but wanted to share my findings thus far.

> cordova-fetch npm install --production clobbers node_modules, causes workflow issues
> ------------------------------------------------------------------------------------
>                 Key: CB-13540
>                 URL:
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-fetch
>            Reporter: Alex Matchneer
>            Priority: Minor
>              Labels: fetch, node_modules, npm
> I have tried and failed to provide a reproduction of this issue and have hence written/deleted/rewritten
this issue many times without submitting, but now I'm going to just submit it, hope for feedback,
and continue to try and reproduce:
> Basically, since this issue (, cordova-fetch
uses the `--production` flag with `npm install`, which tells npm not to install any "devDependencies".

> This seems like a sound approach, but for reasons that I can't reliably reproduced/put
my finger on, it seems like this flag is also aggressively removing packages from `node_modules`,
causing the following workflow issues:
> In my cordova project, I've added `cordova` as a dependency to package.json and encourage
my teammates to use `./node_modules/.bin/cordova` rather than some globally installed `cordova`
executable so that all dependencies are locked down and we don't have to fight the dependency
hell of global CLI dependencies + local package.json dependencies.
> Now, when I freshly clone a repo, do an npm install, and then run `./node_modules/.bin/cordova
prepare`, it will non-deterministically fail with the following output:
> {code}
> Discovered platform "ios@^4.5.3" in config.xml or package.json. Adding it to the project
> Using cordova-fetch for cordova-ios@^4.5.3
> Error: Failed to fetch platform cordova-ios@^4.5.3
> Probably this is either a connection problem, or platform spec is incorrect.
> Check your connection and platform name/version/URL.
> Failed to get absolute path to installed module
> Error: No platforms added to this project. Please use `cordova platform add <platform>`.
> {code}
> And when I look at node_modules, most of my dependencies have been deleted, and in particular,
there's no more `node_modules/.bin/cordova` executable.
> My best guess is that the `npm install --production --no-save` that cordova-fetch internally
does is nuking a bunch of dependencies considering "non-production", including the cli folder
itself. The remedy is to use a globally installed cordova CLI executable, which somehow avoids
these issues.
> Both my local and global cordova executables are 7.7.4.
> I will continue to try and provide a consistent reproduction of this issue; I've tried
and failed many times and I'm starting to pull my hair out. I just wanted to officially post
this issue in case other people have seen it, have advice, or have had better luck reproducing.

This message was sent by Atlassian JIRA

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message