4

I generate an application as suggested by https://github.com/nativescript-vue/vue-cli-template:

vue init nativescript-vue/vue-cli-template test03
cd test03

npm install

tns build android

tns preview

At preview stage, I get the following error:

LOG from device HUAWEI P10 lite: com.tns.NativeScriptException: Error calling module function
TypeError: Cannot read property 'on' of undefined
File: "file:///data/data/org.nativescript.preview/files/app/vendor.js, line: 3254, column: 2085

StackTrace:
        Frame: function:'srcBackendJs', file:'file:///data/data/org.nativescript.preview/files/app/vendor.js', line: 3254, column: 2086
        Frame: function:'__webpack_require__', file:'file:///data/data/org.nativescript.preview/files/app/vendor.js', line: 12, column: 27
        Frame: function:'', file:'file:///data/data/org.nativescript.preview/files/app/vendor.js', line: 27, column: 16
        Frame: function:'../node_modules/@vue/devtools/build/backend.js', file:'file:///data/data/org.nativescript.preview/files/app/vendor.js', line: 27, column: 88
        Frame: function:'__webpack_require__', file:'file:///data/data/org.nativescript.preview/files/app/runtime.js', line: 751, column: 30
        Frame: function:'fn', file:'file:///data/data/org.nativescript.preview/files/app/runtime.js', line: 121, column: 20
        Frame: function:'connect', file:'file:///data/data/org.nativescript.preview/files/app/vendor.js', line: 6334, column: 5
        Frame: function:'setupDevtools', file:'file:///data/data/org.nativescript.preview/files/app/vendor.js', line: 7417, column: 16
        Frame: function:'Vue.$start', file:'file:///data/data/org.nativescript.preview/files/app/vendor.js', line: 7441, column: 7
        Frame: function:'', file:'file:///data/data/org.nativescript.preview/files/app/bundle.js', line: 329, column: 4
        Frame: function:'./main.ts', file:'file:///data/data/org.nativescript.preview/files/app/bundle.js', line: 335, column: 30
        Frame: function:'__webpack_require__', file:'file:///data/data/org.nativescript.preview/files/app/runtime.js', line: 751, column: 30
        Frame: function:'checkDeferredModules', file:'file:///data/data/org.nativescript.preview/files/app/runtime.js', line: 44, column: 23
        Frame: function:'webpackJsonpCallback', file:'file:///data/data/org.nativescript.preview/files/app/runtime.js', line: 31, column: 19
        Frame: function:'', file:'file:///data/data/org.nativescript.preview/files/app/bundle.js', line: 2, column: 57
        Frame: function:'require', file:'', line: 1, column: 266


TypeError: Cannot read property 'on' of undefined
        at com.tns.Runtime.runModule(Native Method)
        at com.tns.Runtime.runModule(Runtime.java:663)
        at com.tns.Runtime.run(Runtime.java:655)
        at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1122)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6619)
        at android.app.ActivityThread.-wrap2(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:108)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:7529)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

I ran on Windows 10 and phone is Android Huawei.

vue --version
3.11.0

I tried with both Javascript and TypeScript, vuex both yes and no, and scheme none and light. None work.

John Zen
  • 81
  • 4

3 Answers3

2

I get a response from Igor on Nativescript community slack. He mentioned that I enabled the vue devtools option when generating the application.

I re-generated an app select No on vue devtools, everything works.

John Zen
  • 81
  • 4
0

I have created a new test project here, followed all the steps and worked well.

Your possible further options:

  1. Clear the previous installation
  2. Follow the installation guide again but consider installing globally with npm (npm -g)
  3. check tns doctor to see if all the requirements are installed and up to date ({N} 6.1 was released sept 3rd)
  4. When all done, generate the new project with what you need
  5. Install local dependencies with yarn (yarn handles Vue projects very well) - yarn install
  6. run tns run android

ps: try to installing AVD or connect to a real device to be sure that works

Nero
  • 36
  • 6
  • Thanks @MatheusFelipe. I get a response from Igor on slack channel. The reason is that I enabled vue devtools when generating the App. I add a answer below for the benefit of others. – John Zen Sep 08 '19 at 06:32
0

I had the same error. It is caused by the package @vue/devtools interacting with nativescript-socketio when the VueDevTools are used.

To fix it, uninstall the package nativescript-socketio from the devDependencies and install it back as a normal dependency:

yarn remove nativescript-socketio && yarn add nativescript-socketio
belvederef
  • 2,195
  • 19
  • 16