1

I don't know what I did wrong, but it says Syntax error with codes copy pasted from official ionic2 docs.

SyntaxError: D:/Manson/Arts/Ionic/IonicTodo2/app/pages/list/list.js: Unexpected token (14:23) while parsing file: D:\Manson\Arts\Ionic\IonicTodo2\app\pages\list\list.js

For the full code click here.

    constructor(nav: NavController) {
0

1 Answer 1

1

It looks like you're using types from Typescript, while your code is in a plain Javascript file (.js). nav: NavController declares that nav is of type NavController.

When you run ionic serve, Ionic runs webpack to compile and package your code. Since this is not a valid JS syntax, it fails.

Ionic 2 is based on Angular 2, which was written in Typescript. While Angular 2 can be used with plain Javascript, it is mostly undocumented, and they basically recommend using Typescript when developing Angular 2 applications.

When you create a new Ionic 2 project, you should use the --ts flag if you want your project to be in Typescript. The command should be:

ionic start MyIonic2Project --v2 --ts

After that, copy-pasting the Ionic 2 tutorials should work for you.

Sign up to request clarification or add additional context in comments.

2 Comments

so how would I convert my current application to a typescript one? :)
If you haven't written a lot of code, I think it will be easier to start a new project and copy whatever you have to it. Otherwise you will probably need to manually change .js files to .ts files and also configure webpack appropriately, which is not very intuitive.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.