Using NativeScript Plugins with AppBuilder

2 posts, 0 answers
  1. Ian
    Ian avatar
    129 posts
    Member since:
    Jun 2009

    Posted 26 Nov 2015 Link to this post

    Hi,

    Has anybody got an NPM plugin with NativeScript working with AppBuilder yet? I’ve used the ‘Manage packages’ screen in AB to include the nativescript-ios-uuid plugin in my app and the plugin is correctly listed as a dependency in the app’s packages.json file. However, when I use require("nativescript-ios-uuid") in my code I get a ‘Failed to find module’ runtime error.

    I’ve tried require("../nativescript-ios-uuid") and numerous other path options but no luck. Does anybody know what the correct path should be to 'require' a {N} plugin?

    Thanks, Ian

  2. Ian
    Ian avatar
    129 posts
    Member since:
    Jun 2009

    Posted 27 Nov 2015 in reply to Ian Link to this post

    In case it helps somebody else, I worked out what was going wrong here. The nativescript-ios-uuid plugin only works on iOS devices and you have to be careful to ensure that you both ‘require’ the plugin AND call its getUUID() method ONLY on an iOS device.

    That's why the following code generated the ‘File not found’ error on iOS platforms:
    var plugin = require("nativescript-ios-uuid");
    if (page.ios) {
        var deviceId = plugin.getUUID();
    }

    However, this works on iOS:
    if (page.ios) {
        var plugin = require("nativescript-ios-uuid");
        var deviceId = plugin.getUUID();
    }
    Regards, Ian
Back to Top