Unexpected token import



I’m trying to use the Exit plugin, here’s what I do:

  • tns create exitApp
  • cd exitApp\
  • npm install nativescript-exit --save

I only add:
import {exit} from ‘nativescript-exit’;
to the top of the main-page.js file, and then after:

  • tns run android

I get an error: unexpected token import


Do you really need a plugin to do this? you can do it directly in your code

var application = require("application");
if (application.android) {
} else if (application.ios) {

here is a quick playground


I need to get the job done :slight_smile:

Your solution is interesting, but it seems to minimize the app, not actually kill it (at least on my android emulator)


The plugin you mentioned also uses just one line of code, you may try that directly.


Besides, you had mentioned that you used

import {exit} from ‘nativescript-exit’;

in main-page.js. As @Pete.K mentioned at ECMAScript 6 (ES6) importing problems Android Runtime doesn’t support the fancy es6 import statement. You have to use require or migrate to TypeScript.


Seems to be working, so I guess the final code will be:

if (application.android) {
    } else if (application.ios) {


And if you want to require that plugin in JS,
it would be

const exit = require("nativescript-exit").exit;


Thanks, but is there really a need for using a plugin for it if we have a few lines of code doing the exit? Do you think it’s better to use a plugin?


No because the lines above are same as in the plugin

look here is android implementation in the plugin

and here is the iOS

its literally only two lines plugin :slight_smile:


Great, so my problem with the “unexpected token import” was related to using TS specific code in a core app, instead of a require. But in the end the exit functionality can be solved much easier, without plugins.


Yeah, I agree with @ganas
There is no need to use that plugin