Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 - 'import' and 'export' may appear only with 'sourceType: module'

Working on a new project with a very fresh install of ionic2 ,after install angular2-jwt I am getting this error:

ParseError: 'import' and 'export' may appear only with 'sourceType: module'

D:\desenv\arquivos\workspace_inbit\medipop-parent\medipop-app\node_modules\angular2-jwt\angular2-jwt.ts:1
import {Injectable, Injector} from 'angular2/core';

To reproduce:

ionic start testapp --v2 --ts 
cd testapp
npm i --save angular2-jwt

and the app page:

@App({
    templateUrl: 'build/app.html',
    providers: [
        provide(AuthHttp, {
            useFactory: (http) => {
                return new AuthHttp(new AuthConfig({
                    headerPrefix: '',
                    noJwtError: true
                }), http);
            },
            deps: [Http]
        })
    ]
})
class MyApp {}

Does anyone have a clue of how to solve this little puzzle?

like image 704
Marcos J.C Kichel Avatar asked Apr 05 '16 22:04

Marcos J.C Kichel


1 Answers

Try to add this line to your ts config:

"parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module"
},

If this doesn't work, try with this config wich is working on my computer (tsconfig.json):

{
    "compilerOptions": {
        "noImplicitAny": true,
        "module": "commonjs",
        "target": "ES5",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "sourceMap": true,
        "declaration": true,
        "moduleResolution":"node"
    },
    "files": [
        "angular2-jwt.ts",
        "typings/browser.d.ts",
        "custom.d.ts"
    ]
}
like image 199
Sylvain Martin Avatar answered Nov 09 '22 19:11

Sylvain Martin