Error in building in NativeScript Ng2 App - Failed to find Module


#1

Hi,
I am trying to build a native script ng2 project using algolia search and algolia search helper from npm. These node modules appear to have a tty dependency.
Tell us about the problem
When I try to run the project I am getting the following error:
Error: com.tns.NativeScriptException: Failed to find module: “tty”, relative to: app/tns_modules/

(Full log below)
I tried to solve this by searching Stack Overflow and the other issues in this forum.
Based on the suggestions, I tried the following with no success:

a. delete npm, platform and hooks and reinstall
b. checked whether tty dependency is in package.json (it is)

Please suggest what I could try.

Search is very important to our app and alogolia is preferred.

Which platform(s) does your issue occur on? Android (haven’t tried on iOS yet)
Iam using:
CLI: 2.5.0Cross-platform modules: 2.5.0Runtime(s): “tns-android”: version 2.5.0Plugin(s):
package.json dependencies are:

“dependencies”: {
"@angular/common": “2.4.3”,
"@angular/compiler": “2.4.3”,
"@angular/core": “2.4.3”,
"@angular/forms": “2.4.3”,
"@angular/http": “2.4.3”,
"@angular/platform-browser": “2.4.3”,
"@angular/platform-browser-dynamic": “2.4.3”,
"@angular/router": “3.4.3"
@types/algoliasearch": “^3.18.0”,
“algoliasearch”: “^3.22.1”,
“nativescript-angular”: “1.4.0”,
“nativescript-theme-core”: “~1.0.2”,
“reflect-metadata”: “~0.1.8”,
“rxjs”: “~5.0.1”,
“tns-core-modules”: “2.5.0”,
“tty”: “^1.0.1”
},

“devDependencies”: {
“babel-traverse”: “6.4.5”,
“babel-types”: “6.4.5”,
“babylon”: “6.4.5”,
“lazy”: “1.0.11”,
“nativescript-dev-android-snapshot”: “^0…”,
“nativescript-dev-typescript”: “^0.3.5”,
“typescript”: “~2.1.0”,
“zone.js”: “~0.7.2”
}

Error log below
`An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: 

Error calling module function 
Error calling module function 
Error calling module function 
Error calling module function 
Error calling module function 
Error calling module function 
Error calling module function 
Error calling module function

Error: com.tns.NativeScriptException: Failed to find module: "tty", relative to: app/tns_modules/
    com.tns.Module.resolvePathHelper(Module.java:159)
    com.tns.Module.resolvePath(Module.java:60)
    com.tns.Runtime.runModule(Native Method)
    com.tns.Runtime.runModule(Runtime.java:580)
    com.tns.Runtime.run(Runtime.java:574)
    com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:17)
    android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)
    android.app.ActivityThread.handleBindApplication(ActivityThread.java:4726)
    android.app.ActivityThread.access$1600(ActivityThread.java:153)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:148)
    android.app.ActivityThread.main(ActivityThread.java:5438)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
File: "<unknown>, line: 1, column: 265

StackTrace: 


            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/tns_modules/debug/node.js', line: 6, column: 11
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/tns_modules/debug/index.js', line: 9, column: 20
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/tns_modules/algoliasearch/src/server/builds/node.js', line: 6, column: 13
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/tns_modules/algoliasearch/index.js', line: 6, column: 18
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/services/algolia.service.js', line: 3, column: 21
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/app.component.js', line: 3, column: 25
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/app.module.js', line: 4, column: 23
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/main.js', line: 3, column: 20
            Frame: function:'require', file:'', line: 1, column: 266

Error: com.tns.NativeScriptException: Failed to find module: "tty", relative to: app/tns_modules/
    com.tns.Module.resolvePathHelper(Module.java:159)
    com.tns.Module.resolvePath(Module.java:60)
    com.tns.Runtime.runModule(Native Method)
    com.tns.Runtime.runModule(Runtime.java:580)
    com.tns.Runtime.run(Runtime.java:574)
    com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:17)
    android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)
    android.app.ActivityThread.handleBindApplication(ActivityThread.java:4726)
    android.app.ActivityThread.access$1600(ActivityThread.java:153)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:148)
    android.app.ActivityThread.main(ActivityThread.java:5438)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
File: "<unknown>, line: 1, column: 265

StackTrace: 
           Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/tns_modules/debug/node.js', line: 6, column: 11
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/tns_modules/debug/index.js', line: 9, column: 20
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/tns_modules/algoliasearch/src/server/builds/node.js', line: 6, column: 13
            Frame: function:'require', file:'', line: 1, column: 266
           Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/tns_modules/algoliasearch/index.js', line: 6, column: 18
            Frame: function:'require', file:'', line: 1, column: 266
           Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/services/algolia.service.js', line: 3, column: 21
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/app.component.js', line: 3, column: 25
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/app.module.js', line: 4, column: 23
            Frame: function:'require', file:'', line: 1, column: 266
            Frame: function:'', file:'file:///data/data/org.nativescript.Testing/files/app/main.js', line: 3, column: 20
            Frame: function:'require', file:'', line: 1, column: 266

#2

I am experiencing the same Error: com.tns.NativeScriptException: Failed to find module: error with the package apollo-angular in a NativeScript-Angular project using CLI versions 2.5.1-2.5.4. I verified that the apollo-angular package is present in node_modules and know it is valid, as the same package loads under a shared Angular browser project.

However, in my case I found I could resolve the error by adding apollo-angular (and then a few other problematic packages) to the NativeScript project package.json (in our project, they were not present, as they were installed via a node_modules shared with the browser project).

I don’t understand how the NativeScript CLI resolves modules. TypeScript was able to find the modules without issue and there are many other modules that are loaded without being listed in the NativeScript package.json, so I am curious why only a few needed to be listed there in order to be found.

Update: I think this Github issue comment on how the NativeScript CLI copies node_modules dependencies explains what was happening in my case, though not in Katy’s: In my case, the packages unspecified in package.json were also peer dependencies of other specified packages and were therefore present in node_modules and copied into the build by NativeScript CLI.


#3

Thanks Keith. Unfortunately in our case tty is present in package.json and in the node_modules folder. So this solution is unlikely to work for us.
I have experienced what you say, for some plugins like the nativescript firebase plugin, I had to add it package.json and then run npm install.
Thanks for the input!


#4

there’s a new Algolia plugin to use, http://plugins.nativescript.org/plugin/nativescript-algolia - to help with the first question. It seems very solid per my recent usage.