"Failed to find module" error when trying to include package from npm

4 posts, 0 answers
  1. Ryan
    Ryan avatar
    18 posts
    Member since:
    Dec 2012

    Posted 08 Dec 2016 Link to this post

    I installed this package and its dependencies from the npm: https://www.npmjs.com/package/nativescript-orientation

    And then tried to require it using require("nativescript-orientation") but I get an error saying that it failed to find the module relative to /app/tns_modules/

    Here is what my package.json file looks like:

    {
        "nativescript": {},
        "dependencies": {
            "tns-core-modules": "2.3.0",
            "nativescript-orientation": "1.5.4",
            "nativescript-dom": "1.0.8",
            "nativescript-globalevents": "1.1.2"
        },
        "devDependencies": {}
    }     

     

    Am I missing a step here?

  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    558 posts

    Posted 13 Dec 2016 Link to this post

    @Ryan

    I was able to correctly use the module added as a dependency in my Telerik Platform NativeScript project. The important point here is that you need to deploy the app as an application package on a device. Please ensure that you are doing so because the error pretty much resembles such thrown from the developer app for rapid on device testing. More on this topic here.

    For best results and especially when using custom plugins/modules - deploy and test your app as an actual package on a device. More on this matter can be found here.

    Here is my configuration and code just as a reference:
    {
      "nativescript": {},
      "dependencies": {
        "tns-core-modules": "2.3.0",
        "nativescript-orientation": "1.5.4"
      },
      "devDependencies": {}
    }

      var orientation = require('nativescript-orientation');
     
    .....
     
    ////
     
    alert(orientation.getOrientation());  // landscape / portrait

    I hope this helps.

    Regards,
    Anton Dobrev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Ryan
    Ryan avatar
    18 posts
    Member since:
    Dec 2012

    Posted 13 Dec 2016 Link to this post

    Thank you Anton, that was definitely the issue. It works when deployed as an app.

     

    Is there a way to use modules with the developer app though? It is much easier to test with it, especially on iOS devices.

  4. Anton Dobrev
    Admin
    Anton Dobrev avatar
    558 posts

    Posted 16 Dec 2016 Link to this post

    @Ryan

    Glad to hear that the issue was resolved.

    I completely feel your point here, however, a developer cannot manually add a plugin to the developer app, it comes bundled with a set of plugins which are usually updated regularly. With the velocity NativeScript plugins are being published it may be hard to maintain and catch up with the speed of this though. That is why my suggestion would be to consider deploying as a package (and then LiveSync the changes to the device) when introducing new changes in your app.

    Regards,
    Anton Dobrev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top