我在使用项目中 ionic 2 项目之外的自己的 typescript 文件时遇到问题。我有一个我想使用的身份验证模块,但它无法正常工作。我不确定这是 typescript 设置问题还是 ionic 问题。
app.module.ts
import { NgModule } from '@angular/core';
import {IonicApp, IonicModule} from 'ionic-angular';
import { MyApp } from './app.component';
import { LoginComponent } from './login/login.component';
import {AuthModule} from "../../../web/src/shared/services/auth/auth.module";
@NgModule({
declarations: [
MyApp,
LoginComponent
],
imports: [
IonicModule.forRoot(MyApp),
AuthModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
LoginComponent
],
providers: [
]
})
export class AppModule {}
tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["dom", "es2015"]
},
"exclude": ["node_modules"],
"compileOnSave": false,
"atom": { "rewriteTsconfig": false }
}
auth.module.ts
import {NgModule} from "@angular/core";
import {HttpModule} from "@angular/http";
import {IdentityService} from "./identity.service";
import {IdentityEventService} from "./identity-event.service";
@NgModule({
imports: [HttpModule],
providers: [
IdentityService,
IdentityEventService
]
})
export class AuthModule {
}
我收到以下错误:
[14:34:24] 捆绑失败:..../web/src/shared/services/auth/auth.module.ts 中的意外字符“@”(5:0)
所以它看起来好像正在找到包,但在 NgModule 声明中窒息。如果我删除对 auth.module
的引用,它将起作用。我已经将 auth 模块需要的所有包添加到我的 ionic 项目的 package.json 文件中,因此引用应该不是问题。
如果需要更多相关信息来调试它,请告诉我。
最佳答案
我在制作我的第一个 ionic2 应用程序时遇到了同样的问题。我发现当我将我的提供程序(标记为@injectable)导入到 app.module.ts 时,它们被导入为“../authservice.ts”等而不是“../authservice”。检查是否是这种情况并删除 .ts .. im on ionic 2.1.0
关于angular - Ionic 2/Typescript 构建失败 : Unexpected character '@' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40163312/