This is a migrated thread and some comments may be shown as answers.

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

3 Answers 118 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ryan
Top achievements
Rank 1
Ryan asked on 08 Dec 2016, 08:38 PM

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?

3 Answers, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 13 Dec 2016, 08:42 AM
@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
0
Ryan
Top achievements
Rank 1
answered on 13 Dec 2016, 02:41 PM

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.

0
Anton Dobrev
Telerik team
answered on 16 Dec 2016, 10:58 AM
@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
Tags
General Discussions
Asked by
Ryan
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or