Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

npm dependencies conflict. TypeError: xml2js.Builder is not a function. #27

Closed
alexbuijs opened this issue Dec 17, 2015 · 8 comments
Closed
Labels

Comments

@alexbuijs
Copy link

Hi,

I ran into a problem with your custom dependency resolve mechanism in the afterPrepareHook. When it is run, it checks for the presence of dependent modules. It doesn't check for versions, however. As it happens, I have the xml2js module installed as a child dependency of another one of your plugins ;-)

> npm list xml2js
└─┬ [email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └── [email protected]

Now, since xml2js.Builder is a function available from xml2js > 4.0, I get the following error when preparing my project:

TypeError: xml2js.Builder is not a function
  at Object.writeJsonAsXml (/builds/youngcapital/youngcapital_mobile/plugins/cordova-universal-links-plugin/hooks/lib/xmlHelper.js:46:22)
  at Object.writePreferences (/builds/youngcapital/youngcapital_mobile/plugins/cordova-universal-links-plugin/hooks/lib/android/manifestWriter.js:34:15)
  at activateUniversalLinksInAndroid (/builds/youngcapital/youngcapital_mobile/plugins/cordova-universal-links-plugin/hooks/afterPrepareHook.js:59:25)
  at /builds/youngcapital/youngcapital_mobile/plugins/cordova-universal-links-plugin/hooks/afterPrepareHook.js:39:11
  at Array.forEach (native)
  at run (/builds/youngcapital/youngcapital_mobile/plugins/cordova-universal-links-plugin/hooks/afterPrepareHook.js:35:17)
  at module.exports (/builds/youngcapital/youngcapital_mobile/plugins/cordova-universal-links-plugin/hooks/afterPrepareHook.js:18:3)

My solution for this problem was to add the latest version of xml2js to my projects package.json, so the latest version is available for the plugin. But perhaps it is possible you could prepackage the dependencies inside the plugin, instead of reinventing npm? :-)

@nikDemyankov
Copy link
Member

Hi,

I don't think that it's a good idea to prepackage dependencies inside the plugin. For same reason I then need to prepackage cordova and ios/android platforms also :) I had to reinvent npm for plugin because cordova doesn't install dependent modules (at least for now). But thanks for noticing that, will think of something, although it's strange that I didn't hit the same issue...

@alexbuijs
Copy link
Author

It is strange that you haven't encountered this before. I imagine it could also have something to do with bugs in the current NPM version. I am on the latest right now, 3.5.2, and it even wouldn't allow me to add xml2js as a separate dependency, giving warnings such as these:

npm WARN skippingAction Module is inside a symlinked module: not running add [email protected] node_modules/aws-sdk/node_modules/xml2js

and:

npm WARN update-linked node_modules/xml2js needs updating to 0.4.15 from 0.2.8 but we can't, as it's a symlink

There are open bugs for it, like: npm/npm#9999 and npm/npm#10013.

I fixed this by removing all installed modules and reinstalling them again.

If prepackaging just the modules you require in the hooks (e.g. mkpath, rimraf and xml2js), (not entire cordova ;-) is not an option, then at least this issue can be found for others how may run into this problem.

@nikDemyankov
Copy link
Member

I am using v2.14.7, maybe that's why I didn't hit that. Good that you solved it)

@nikDemyankov nikDemyankov changed the title TypeError: xml2js.Builder is not a function NPM dependencies conflict. TypeError: xml2js.Builder is not a function. Dec 18, 2015
@nikDemyankov nikDemyankov changed the title NPM dependencies conflict. TypeError: xml2js.Builder is not a function. npm dependencies conflict. TypeError: xml2js.Builder is not a function. Dec 18, 2015
@nikDemyankov nikDemyankov added this to the v1.2.0 milestone Apr 5, 2016
@luisaccedo
Copy link

Samething happens to me... I get Error: Cannot find module 'xml2js' on 'cordova build'

@nikDemyankov
Copy link
Member

Understood... will change the way how dependency modules are installed to fix this issue. For now try the following:

  1. Go to your project's root folder.
  2. Remove xml2js: npm uninstall xml2js.
  3. Install it: npm install xml2js.

@nikDemyankov
Copy link
Member

@luisaccedo Uploaded updated version of the plugin in the repo. Possible, should fix issue with xml2js. Just remove the plugin, and then install it again with:

cordova plugin add https://github.com/nordnet/cordova-universal-links-plugin.git

@luisaccedo
Copy link

fixed!

muchísimas gracias!

@nikDemyankov nikDemyankov removed this from the v1.2.0 milestone Apr 27, 2016
@nikDemyankov
Copy link
Member

Good :) Released v1.1.2 with the fix. Closing the issue. Please, reopen it, if problem persist.

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

No branches or pull requests

3 participants