1

I create a new nativescript application (ns create xxxx) and then run it to get it loaded into a simulator (ns run ios).

Once running, I add a console log anywhere (on init, or as an action from a button click etc.) and it will not output to the console.

I have found a thread on Stack that posed a similar question but it looks like they never got much feedback (and others reported the issue).

I have tried running in the VSCode terminal as well as the regular terminal (so it's not a VSCode thing). I am completely floored on what could be causing this.

  • If you're expecting the logs to show up in Chrome dev tools (which I suspect you are), you'll not find it there. Look in the terminal you're running the app from. – Ben Brookes Feb 08 '21 at 16:25

3 Answers3

2

This looks strange because console.logs usually work ok. Please check the following

  1. Be sure that you do not run your application in release mode or with --env.uglify flag because it may cause drop logging

  2. Disable hot module replacement option. Sometimes it cause issues.

  3. Be sure to use correct console operations. For example console.debug is not supported. You can find full list here

  4. Remove node_modules, platforms and hooks folders before next run. Just in case.

  5. Don't you have console object overridden by some other object?

  6. Try to change your console.log command with alert and check if it works.

Please, come back after your check all the points from this checklist, also please add the report from your ns doctor command, and let's see if we can move on

Update:

Since you're using MacBook based on M1 processor it seems that your question is related to this issue:

https://github.com/NativeScript/nativescript-cli/issues/5454

Unfortunately, the only advice I can give you for now is to follow the thread for some solution or workarounds

Sergey Mell
  • 7,780
  • 1
  • 26
  • 50
  • Ok, so I'm not (actively) running in release mode. I tried runnning with HMR off and same behavior. I am only trying console.log("hello"); I don't know what you mean by having the console object overridden but as I mentioned, I've done this from a fresh (ns create) project. Finally I have used alert instead of console.log and I do get the alert without an issue. NS Doctor shows all good. Only additional information I can provide is that I'm on a new computer that I just bought (macbook pro). So it's freshly installed everything (VSCode, nativescript, node, etc.) – user1684600 Feb 08 '21 at 16:30
  • ok, try to remove `node_modules`, `platforms` and `hooks` folders before the next run and change `console.log` to `alert` to see if this line of code is really called – Sergey Mell Feb 08 '21 at 16:32
  • Is your MacBook based on an M1 processor? – Sergey Mell Feb 08 '21 at 16:45
  • Yes, it's an M1. I had to install node twice (once under ARM and again under Darwin). But I have everything else working as best I can tell. The app launches in the simulator it just doesn't show any console.log messages. I did remove the above folders (via ns clean) and rebuilt...tried with Alert and it works, tried with console.log and nothing – user1684600 Feb 08 '21 at 16:51
  • Seems your problem is related to https://github.com/NativeScript/nativescript-cli/issues/5454. Follow this thread for some updates or workarounds. That's all I can help for now, unfortunately. In case you find a solution that helps, I appreciate if you share it with me. – Sergey Mell Feb 08 '21 at 16:54
  • Thank you for your help. So it must be related to that. I tried the command provided in the thread to log to a different terminal (the log stream command) and that does show my logs although I didn't follow how to 'pipe it to sed/awk' as instructed. But it does show something. – user1684600 Feb 08 '21 at 20:29
  • Final comment on this, rolling back to a previous iOS version on the simulator does show the messages. This link shows how to do that: https://stackoverflow.com/questions/4262018/xcode-simulator-how-to-run-older-ios-version#:~:text=To%20run%20an%20older%20iOS,and%20to%203.2%20for%20iPad. – user1684600 Feb 08 '21 at 20:56
2

I'm joining in a bit later, but this might help someone else who's having the same issue while also using the M1 based processors.

For me, using console.log() (on iOS) didn't show any output in Visual Studio Code, but it did show up in a separate Xcode build. So the output is definitely out there.

I came across a SO answer a while ago (don't remember which one exactly) that had this workaround which shows the output in a separate terminal window.

Suppose we have this: enter image description here

Open a new terminal window (preferably outside of VS Code. You'll see why in a second), and run this command:

log stream --level debug --predicate 'senderImagePath contains "NativeScript"'

It'll show the output in the terminal window as shown below:

enter image description here

Now, I honestly think this would be easier to read (especially when you're logging JSON data on a smaller screen) if everything in between the timestamp and "CONSOLE LOG" was excluded. Unfortunately I haven't figured out how to do that yet.

tysab
  • 31
  • 1
1

I solved the problem by changing the Vue.config.silent which is by default set to true to false.

You can add Vue.config.silent = false; inside your app.js before new Vue(...)

Ex:

import Vue from 'nativescript-vue'

import Home from './components/Home'

Vue.config.silent = false;

new Vue({
  render: (h) => h('frame', [h(Home)]),
}).$start()

Happy coding!

Rohit Nair
  • 628
  • 3
  • 7
  • 22