使用ionic2全新安装的新项目,在安装angular2-jwt之后,我得到此错误:

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';

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

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

有人知道如何解决这个小难题吗?

最佳答案

尝试将此行添加到您的ts配置中:

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

如果这不起作用,请尝试在我的计算机上使用此配置(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"
    ]
}

关于cordova - ionic 2- 'import'和 'export'可能仅与 'sourceType: module'一起出现,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36438191/

10-08 21:22