使用新安装的ionic2处理新项目,安装angular2-jwt后我收到此错误: ParseError: 'import' and 'export' may appear only with 'sourceType: module'D:\desenv\arquivos\workspace_inbit\medipop-parent\medipop-app\node_modules\angular
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" ] }