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

Error during plugin restore: Cannot find module 'tostr' #89

Closed
sinedied opened this issue Nov 14, 2016 · 9 comments
Closed

Error during plugin restore: Cannot find module 'tostr' #89

sinedied opened this issue Nov 14, 2016 · 9 comments

Comments

@sinedied
Copy link

sinedied commented Nov 14, 2016

Hello,

Each time I try to restore this plugin using a cordova prepare command, I get this error:

cordova-custom-config: Error loading dependencies (Cannot find module 'tostr') - attempting to resolve
cordova-custom-config: npm dependencies missing - installing
cordova-custom-config: Installed npm dependencies

The thing is, the dependency toatr does not get installed even though it says so and crash the build. If I install it manually, I have no issues, so it seems like there is an issue with your npm install script?

This is quite problematic on my CI build, for now I have a workaround executing npm install tostr after the cordova prepare command, but it's not quite right.

Could you look into this issue?
Thanks!

My env:

  • cordova 6.4.0
  • node 5.0.0
  • npm 3.10.3
@dpa99c
Copy link
Owner

dpa99c commented Nov 23, 2016

I've not been able to reliably reproduce this, which leads me to believe a race condition may be involved between the Cordova hooks which are executed on running cordova prepare, namely that the after_prepare hook is running before the after_plugin_install hook has finished installing packages.

@dpa99c
Copy link
Owner

dpa99c commented Nov 23, 2016

I've added a workaround which should cause the after_prepare script to make another attempt at installing dependencies if there are missing. This should cause enough of a delay for the original install operation to complete, so the second attempt to resolve dependencies should succeed. This will be published in cordova-custom-config@3.1.0

@sinedied
Copy link
Author

Nice, I hope it will fix the issue. I'm steadily reproducing this on my project base on this starter kit which use Ionic, if you need a test base.

@dpa99c
Copy link
Owner

dpa99c commented Nov 26, 2016

Should be fixed in cordova-custom-config@3.1.0
If you're still having issues, let me know and I'll reopen and investigate further.

@dpa99c dpa99c closed this as completed Nov 26, 2016
@sandstream
Copy link

Don't work with 3.1.0.

@samkelleher
Copy link

Just to chime in, using 3.1.2 and also seeing this issue:

cordova-custom-config: Error loading dependencies (Cannot find module 'tostr') - attempting to resolve

Haven't figured out how to do this in CI, but I just run npm install tostr to resolve it for now.

@MarsupiL
Copy link

MarsupiL commented Jun 13, 2017

This seems to still be an issue in cordova-custom-config@3.3.0
I'm running the cordova project inside a nodejs created tmpdir. It somehow seems to be related.
Cordova-cli: 6.5.0
Node: 8.1.0
npm: 5.0.3

@hortonelectric
Copy link

+1, getting it too. Can somebody shed some light on this?

@dpa99c
Copy link
Owner

dpa99c commented Jun 15, 2017

TL;DR

I would recommend upgrading to cordova@7 (and cordova-custom-config@4).

Your options are:

  • Upgrade Cordova CLI to cordova@7+
  • Use Cordova CLI cordova@6.2+ with --fetch option: cordova plugin install cordova-custom-config --fetch
  • Manually satisfy the dependencies: npm install cordova-custom-config
  • Live with the issue (explained below)

Explanation

This issue occurs due to a race condition when installing cordova-custom-config@3 via the traditional plugin install method (not cordova-fetch). That means if you are using less than cordova@6.2 or less than cordova@7 without using the --fetch option to install.

Until the release of cordova-fetch with cordova@6.2.0, the Cordova CLI provided no mechanism for plugins to install their own npm dependencies. So cordova-custom-config@3 uses a hook script to manually install the dependencies. This returns a Promise which is resolved when all of the dependencies have been installed. However, it seems there is a race condition where the npm install command to install the last dependency in the list - tostr has returned and therefore the promise has resolved, yet the files have not yet been moved from the temporary download location on disk to the target deployment location of node_modules within the Cordova project. So when the tostr dependency is required by the hook script that is used to apply the custom config, this results in an exception which is caught and displays the symptomatic error message. I've tested this scenario multiple times and found the results to be intermittent - sometimes the error occurs, sometimes not - hence my deduction of the race condition.

The latest version of Cordova CLI uses cordova-fetch to install plugins via npm, automatically satisfying module dependencies and therefore the above manual resolution script is no longer necessary.
Hence cordova-custom-config@4 does not contain the above script and relies on installation via cordova-fetch to satisfy its dependencies.

I can foresee a future (cordova@8?) release which deprecates/removes installation of plugins into plugins/&config.xml and relies solely on node_modules/&package.json (cordova@7 by default duplicates plugin installations to both).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants