Failed to find module


#1

I can build and run a template:-
tns create gmc2 --template nativescript-vue-template
cd gmc2
tns run android WORKS OK on android emulator…

I wan to try package IMAP-SIMPLE so
npm install imap-simple --save

and put following line in app.js
var imaps = require(‘imap-simple’);

Now the app crashes on start up with :- Error: com.tns.NativeScriptException: Failed to find module: “tls”, relative to: app/tns_modules (see below)

Surely I don’t have to manually install each sub-dependency? (I tried this and eventually got an even weirder error)

Any ideas?

Peter

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: com.tns.NativeScriptException: Failed to find module: “tls”, relative to: app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:146)
com.tns.Module.resolvePath(Module.java:55)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:530)
com.tns.Runtime.run(Runtime.java:522)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
android.app.ActivityThread.access$1500(ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5254)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
File: ", line: 1, column: 265

StackTrace:
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap/lib/Connection.js’, line: 1, column: 71
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/lib/imapSimple.js’, line: 2, column: 12
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/index.js’, line: 3, column: 18
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/app.js’, line: 2, column: 13
Frame: function:‘require’, file:’’, line: 1, column: 266

Error: com.tns.NativeScriptException: Failed to find module: “tls”, relative to: app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:146)
com.tns.Module.resolvePath(Module.java:55)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:530)
com.tns.Runtime.run(Runtime.java:522)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
android.app.ActivityThread.access$1500(ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5254)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
File: ", line: 1, column: 265

StackTrace:
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap/lib/Connection.js’, line: 1, column: 71
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/lib/imapSimple.js’, line: 2, column: 12
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/index.js’, line: 3, column: 18
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/app.js’, line: 2, column: 13
Frame: function:‘require’, file:’’, line: 1, column: 266

Error: com.tns.NativeScriptException: Failed to find module: “tls”, relative to: app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:146)
com.tns.Module.resolvePath(Module.java:55)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:530)
com.tns.Runtime.run(Runtime.java:522)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
android.app.ActivityThread.access$1500(ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5254)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
File: ", line: 1, column: 265

StackTrace:
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap/lib/Connection.js’, line: 1, column: 71
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/lib/imapSimple.js’, line: 2, column: 12
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/index.js’, line: 3, column: 18
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/app.js’, line: 2, column: 13
Frame: function:‘require’, file:’’, line: 1, column: 266

Error: com.tns.NativeScriptException: Failed to find module: “tls”, relative to: app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:146)
com.tns.Module.resolvePath(Module.java:55)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:530)
com.tns.Runtime.run(Runtime.java:522)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
android.app.ActivityThread.access$1500(ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5254)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
File: ", line: 1, column: 265

StackTrace:
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap/lib/Connection.js’, line: 1, column: 71
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/lib/imapSimple.js’, line: 2, column: 12
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/index.js’, line: 3, column: 18
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/app.js’, line: 2, column: 13
Frame: function:‘require’, file:’’, line: 1, column: 266

Error: com.tns.NativeScriptException: Failed to find module: “tls”, relative to: app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:146)
com.tns.Module.resolvePath(Module.java:55)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:530)
com.tns.Runtime.run(Runtime.java:522)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
android.app.ActivityThread.access$1500(ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5254)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
File: ", line: 1, column: 265

StackTrace:
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap/lib/Connection.js’, line: 1, column: 71
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/lib/imapSimple.js’, line: 2, column: 12
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/index.js’, line: 3, column: 18
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/app.js’, line: 2, column: 13
Frame: function:‘require’, file:’’, line: 1, column: 266

at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4556)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Caused by: com.tns.NativeScriptException:

Error calling module function

Error calling module function

Error calling module function

Error calling module function

Error: com.tns.NativeScriptException: Failed to find module: “tls”, relative to: app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:146)
com.tns.Module.resolvePath(Module.java:55)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:530)
com.tns.Runtime.run(Runtime.java:522)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
android.app.ActivityThread.access$1500(ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5254)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
File: ", line: 1, column: 265

StackTrace:
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap/lib/Connection.js’, line: 1, column: 71
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/lib/imapSimple.js’, line: 2, column: 12
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/index.js’, line: 3, column: 18
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/app.js’, line: 2, column: 13
Frame: function:‘require’, file:’’, line: 1, column: 266

Error: com.tns.NativeScriptException: Failed to find module: “tls”, relative to: app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:146)
com.tns.Module.resolvePath(Module.java:55)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:530)
com.tns.Runtime.run(Runtime.java:522)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
android.app.ActivityThread.access$1500(ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5254)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
File: ", line: 1, column: 265

StackTrace:
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap/lib/Connection.js’, line: 1, column: 71
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/lib/imapSimple.js’, line: 2, column: 12
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/index.js’, line: 3, column: 18
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/app.js’, line: 2, column: 13
Frame: function:‘require’, file:’’, line: 1, column: 266

Error: com.tns.NativeScriptException: Failed to find module: “tls”, relative to: app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:146)
com.tns.Module.resolvePath(Module.java:55)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:530)
com.tns.Runtime.run(Runtime.java:522)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
android.app.ActivityThread.access$1500(ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5254)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
File: ", line: 1, column: 265

StackTrace:
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap/lib/Connection.js’, line: 1, column: 71
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/lib/imapSimple.js’, line: 2, column: 12
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/index.js’, line: 3, column: 18
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/app.js’, line: 2, column: 13
Frame: function:‘require’, file:’’, line: 1, column: 266

Error: com.tns.NativeScriptException: Failed to find module: “tls”, relative to: app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:146)
com.tns.Module.resolvePath(Module.java:55)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:530)
com.tns.Runtime.run(Runtime.java:522)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
android.app.ActivityThread.access$1500(ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5254)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
File: ", line: 1, column: 265

StackTrace:
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap/lib/Connection.js’, line: 1, column: 71
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/lib/imapSimple.js’, line: 2, column: 12
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/index.js’, line: 3, column: 18
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/app.js’, line: 2, column: 13
Frame: function:‘require’, file:’’, line: 1, column: 266

Error: com.tns.NativeScriptException: Failed to find module: “tls”, relative to: app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:146)
com.tns.Module.resolvePath(Module.java:55)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:530)
com.tns.Runtime.run(Runtime.java:522)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
android.app.ActivityThread.access$1500(ActivityThread.java:151)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5254)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
File: ", line: 1, column: 265

StackTrace:
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap/lib/Connection.js’, line: 1, column: 71
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/lib/imapSimple.js’, line: 2, column: 12
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/tns_modules/imap-simple/index.js’, line: 3, column: 18
Frame: function:‘require’, file:’’, line: 1, column: 266
Frame: function:’’, file:‘file:///data/data/org.nativescript.gmc2/files/app/app.js’, line: 2, column: 13
Frame: function:‘require’, file:’’, line: 1, column: 266

at com.tns.Runtime.runModule(Native Method)
at com.tns.Runtime.runModule(Runtime.java:530)
at com.tns.Runtime.run(Runtime.java:522)
at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
... 9 more

#2

tls is a built-in NODE.JS module, therefore, even if you wanted to, you wouldn’t have been able to install it.

Quoting my response on a related question in SO - https://stackoverflow.com/a/46195337/6408287

Note that although both NativeScript and node.js have running JS VMs, they are implemented differently. NativeScript for example does not implement node.js’ built-in modules specification (fs, stream, buffer, net, etc.). That is also the reason why you won’t be able to use most of the node.js modules ‘just like that’.

To use an npm module that relies on built-in node.js modules, you could try replacing the imports and functions yourself, or https://github.com/EddyVerbruggen/nativescript-nodeify#nativescript-nodeify

Bear in mind in NativeScript you can’t use npm modules that manipulate the DOM either.