我正在尝试在Ionic2 / Angular2中开发一个应用程序 我想声明一个简单的模型并获得编译错误 如下。请帮助指出编译错误的原因。
Model1:global.data.ts
import {Injectable} from "angular2/core";
@Injectable
export class GDService{
private _newpost:string;
private _allpost:string;
}
Compilation error:
import {Injectable} from "angular2/core";
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
SyntaxError: global.data.js: Unexpected token (5:9) while parsing file:
Model2:job.mdl.ts
export class Job{
constructor(
id:number,
category:string,
type:string,
details:string
){
}
}
Compilation error:
export class Job{
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
答案 0 :(得分:0)
修改强>
它可能与您的tsconfig文件有关,请确保您在那里定义了一个模块,例如:
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
答案 1 :(得分:-1)
请试试这个兄弟。
而不是这一行
Vect
尝试这样给它
import {Injectable} from "angular2/core";
(请在你的package.json文件中检查一次是否存在@ angular / core依赖。)
希望这会对你有所帮助。祝你有愉快的一天。