加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular2 x-i18n错误:模块导入的意外值

发布时间:2020-12-17 06:59:13 所属栏目:安全 来源:网络整理
导读:我有一个关于Angular2(v2.2.1)和TypeScript的项目,我使用Angular CLI(1.0.0-beta.21).它工作正常.现在我想用Angular i18n添加多语言支持.接下来是官方文档的安装我安装了这个包: npm install @ angular / compiler-cli @ angular / platform-server –save
我有一个关于Angular2(v2.2.1)和TypeScript的项目,我使用Angular CLI(1.0.0-beta.21).它工作正常.现在我想用Angular i18n添加多语言支持.接下来是官方文档的安装我安装了这个包:

npm install @ angular / compiler-cli @ angular / platform-server –save

我跑了这个命令:

“./node_modules/.bin/ng-xi18n”-p src / tsconfig.json

它返回给我错误信息:

Error: Unexpected value 'SharedModule' imported by the module 'AppModule'
at D:Projectscourier-landingpagenode_modules@angularcompilerbundlescompiler.umd.js:14675:33
at Array.forEach (native)
at CompileMetadataResolver._loadNgModuleMetadata (D:Projectscourier-landingpagenode_modules@angularcompilerbundlescompiler.umd.js:14660:51)
at CompileMetadataResolver.getUnloadedNgModuleMetadata (D:Projectscourier-landingpagenode_modules@angularcompilerbundlescompiler.umd.js:14636:23)
at addNgModule (D:Projectscourier-landingpagenode_modules@angularcompilerbundlescompiler.umd.js:12944:43)
at D:Projectscourier-landingpagenode_modules@angularcompilerbundlescompiler.umd.js:12957:16
at Array.forEach (native)
at _createNgModules (D:Projectscourier-landingpagenode_modules@angularcompilerbundlescompiler.umd.js:12956:28)
at analyzeNgModules (D:Projectscourier-landingpagenode_modules@angularcompilerbundlescompiler.umd.js:12700:16)
at Object.analyzeAndValidateNgModules (D:Projectscourier-landingpagenode_modules@angularcompilerbundlescompiler.umd.js:12704:20)

有没有办法解决这个错误或者让其他方法继续国际化?

列出我的AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { SharedModule } from './shared/shared.module';
import { TextMaskModule } from 'angular2-text-mask';

import { HomeComponent } from './landing/home/home.component';
import { LoginComponent } from './landing/login/login.component';
import { SignupComponent } from './landing/signup/signup.component';
import { SignupProfileComponent } from './landing/signup/signup-profile/signup-profile.component';
import { SignupVehicleComponent } from './landing/signup/signup-vehicle/signup-vehicle.component';
import { SignupAreaComponent } from './landing/signup/signup-area/signup-area.component';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent,HomeComponent,LoginComponent,SignupComponent,SignupProfileComponent,SignupVehicleComponent,SignupAreaComponent
  ],imports: [
    BrowserModule,FormsModule,RouterModule.forRoot([
      {
        path: 'login',component: LoginComponent
      },{
        path: 'signup',component: SignupComponent,children: [
          {
            path: '',children: [
              {
                path: 'profile',component: SignupProfileComponent
              },{
                path: 'area',component: SignupAreaComponent
              },{
                path: 'vehicle',component: SignupVehicleComponent
              }
            ]
          }
        ]
      },{
        path: '',component: HomeComponent
      }
    ]),TextMaskModule,SharedModule
  ],providers: [
  ],bootstrap: [AppComponent]
})
export class AppModule { }

SharedModule的列表:

import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { HttpModule } from '@angular/http';
    import { RouterModule } from '@angular/router';

    import { NotificationService,NotificationStream } from './notification.service';
    import { HttpClientService } from './api/http-client.service';
    import { AuthService } from './api/auth.service';
    import { CitiesService } from './api/cities.service';

    import { City } from './models/city';
    import { Notification } from './models/notification';
    import { NotificationType } from './models/notification-type.enum';

    import { NotificationComponent }   from './components/notification/notification.component';

    @NgModule({
      imports: [
        HttpModule,RouterModule,BrowserModule
      ],exports: [
        NotificationComponent
      ],declarations: [NotificationComponent],providers: [
        HttpClientService,AuthService,CitiesService,NotificationStream,NotificationService
      ],})
    class SharedModule { }

    export {
      SharedModule,City,Notification,NotificationType,HttpClientService,CitiesService
    }

P.S.:我在GitHub上发现了许多与此错误相关的问题,但这两种解决方案都不适合我.

解决方法

我找到了解决方案,对我有用.在我的SharedModule中,我从最终导出表达式中删除了SharedModule类,并在NgModule装饰器后面添加了’export’关键字.所以我的SharedModule现在:

import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { HttpModule } from '@angular/http';
    import { RouterModule } from '@angular/router';

    import { NotificationService,})
    export class SharedModule { }

    export {
      City,CitiesService
    }

然后我动了一下,找到了这个问题的原因,以及我发现了什么.Angular CLI使用Webpack编译bundle,ngc使用TypeScript编译器.所以我认为这个问题可能在TypeScript编译器中,但是对于类装饰器不能正常工作.最新的TypeScript编译器版本是2.1.4,Angular CLI使用的是2.0.x版本.我检查了这个并且在将TypeScript编译器更新到2.1.4后,这个问题就消失了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读