代码之家  ›  专栏  ›  技术社区  ›  Julien Rousé sllim.Sam

本地角度构建成功,但Gitlab runner角度构建失败

  •  1
  • Julien Rousé sllim.Sam  · 技术社区  · 7 年前

    我有一个角度的项目,我想在Gitlab页上运行。

    当我跑步时: ng build --prod

    我的 .gitlab-ci.yaml :

    image: node:8.12.0
    
    pages:
      cache:
        paths:
        - node_modules/
    
      stage: deploy
      script:
      - npm install -g @angular/cli@6.2.1
      - npm install
      - ng build
      - mv dist/ProjectName/* public/
      artifacts:
        paths:
        - public
      only:
      - master
    

    当Gitlab CI/CD管道运行时,它会出现以下故障:

    app/app.module.ts(116,5)中的错误:编译的模板时出错

    /构建/JulienRouse/ProjectName/src/app/app.module.ts。。

    src/app/services/Auth.service.ts(3,29):错误TS2307:找不到

    src/app/app.component.ts(6,29):错误TS2307: 找不到模块“./services/user.service”。

    src/app/home/home.component.ts(4,29):错误TS2307:找不到模块

    错误TS2307:找不到模块“../services/user.service”。

    src/app/survey/survey.component.ts(4,29):错误TS2307:找不到

    src/app/infos-recap/infos-recap.component.ts(2,29):错误TS2307: 找不到模块“../services/user.service”。

    src/app/auth/signup/signup.component.ts(5,29):错误TS2307:无法

    src/app/payment/payment-recap/payment-recap.component.ts(2,29):错误

    错误TS2307:找不到模块“../../services/user.service”。

    src/app/payment/payment settings/payment settings.component.ts(4,29): 错误TS2307:找不到模块“src/app/services/user.service”。

    src/app/services/auth guard.service.ts(4,29):错误TS2307:无法 查找模块“./user.service”。

    src/app/services/notAuth guard.service.ts(4,29):错误TS2307:无法 查找模块“./user.service”。

    src/app/services/surveyCompleted guard.service.ts(4,29):错误TS2307:

    src/app/services/surveyNotCompleted guard.service.ts(4,29):错误 TS2307:找不到模块“./user.service”。

    src/app/app.module.ts(23,29):错误TS2307:找不到模块 “./services/user.service”。

    错误:作业失败:退出代码1

    app.module.ts

    这是你的名字 app/app.module.ts :

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { FormsModule, ReactiveFormsModule } from '@angular/forms';
    import { Routes } from '@angular/router';
    import { RouterModule } from '@angular/router';
    import { ExtraOptions } from '@angular/router';
    
    // Component
    import { AppComponent } from './app.component';
    import { HomeComponent } from './home/home.component';
    import { SurveyComponent } from './survey/survey.component';
    import { ResultComponent } from './result/result.component';
    import { InfosRecapComponent } from './infos-recap/infos-recap.component';
    import { SignupComponent } from './auth/signup/signup.component';
    import { SigninComponent } from './auth/signin/signin.component';
    import { DashboardComponent } from './dashboard/dashboard.component';
    import { PaymentRecapComponent } from './payment/payment-recap/payment-recap.component';
    import { PaymentHistoryComponent } from './payment/payment-history/payment-history.component';
    import { PaymentSettingsComponent } from './payment/payment-settings/payment-settings.component';
    import { ProductDescriptionComponent } from './product-description/product-description.component';
    
    // Services
    import { UserService } from './services/user.service';
    import { AuthGuard } from './services/auth-guard.service';
    import { BankService } from './services/Bank.service';
    import { AuthService } from './services/Auth.service';
    import { NotAuthGuard } from './services/notAuth-guard.service';
    import { SurveyCompletedGuard } from './services/surveyCompleted-guard.service';
    import { SurveyNotCompletedGuard } from './services/surveyNotCompleted-guard.service';
    import { ProductService } from './services/Product.service';
    
    // Material Angular
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { MatStepperModule } from '@angular/material/stepper';
    import { MatFormFieldModule } from '@angular/material/form-field';
    import { MatInputModule } from '@angular/material';
    
    // i18n
    import { HttpClientModule, HttpClient } from '@angular/common/http';
    import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
    import { TranslateHttpLoader } from '@ngx-translate/http-loader';
    
    // Charts
    import { NgxChartsModule } from '@swimlane/ngx-charts';
    
    
    
    // AoT requires an exported function for factories
    export function HttpLoaderFactory(http: HttpClient) {
      const url = window.location.href;
    
      if (url.includes('someURL')) {
        return new TranslateHttpLoader(http, '/ProjectName/assets/i18n/', '.json');
      }
      else if(url.includes('someOtherURL')) {
        return new TranslateHttpLoader(http, '/ProjectName/assets/i18n/', '.json');
      }
       else {
        return new TranslateHttpLoader(http);
      }
    }
    
    const appRoutes: Routes = [
      { path: 'home', component: HomeComponent },
      { path: 'signin', canActivate: [NotAuthGuard], component: HomeComponent },
      { path: 'signup', canActivate: [NotAuthGuard], component: HomeComponent },
      { path: 'projectName', canActivate: [AuthGuard, SurveyNotCompletedGuard], component: SurveyComponent },
      // { path: 'result', canActivate:[AuthGuard], component: ResultComponent },
      { path: 'user-update', canActivate: [AuthGuard, SurveyCompletedGuard], component: InfosRecapComponent },
      { path: 'infos-recap', canActivate: [AuthGuard, SurveyCompletedGuard], component: InfosRecapComponent },
      { path: 'dashboard', canActivate: [AuthGuard, SurveyCompletedGuard], component: DashboardComponent },
      { path: 'payment-recap/:id', canActivate: [AuthGuard, SurveyCompletedGuard], component: PaymentRecapComponent },
      { path: 'product-description/:id', canActivate: [AuthGuard, SurveyCompletedGuard], component: ProductDescriptionComponent},
      { path: '', redirectTo: '/home', pathMatch: 'full' },
      { path: '**', redirectTo: '/home' }
    ];
    
    const routerOptions: ExtraOptions = {
      anchorScrolling: 'enabled', // Doesn't work properly on info-recap?
      scrollPositionRestoration: 'enabled',
    };
    
    @NgModule({
      declarations: [
        AppComponent,
        HomeComponent,
        SurveyComponent,
        ResultComponent,
        InfosRecapComponent,
        SignupComponent,
        SigninComponent,
        DashboardComponent,
        PaymentHistoryComponent,
        PaymentRecapComponent,
        PaymentSettingsComponent,
        ProductDescriptionComponent,
      ],
      imports: [
        BrowserModule,
        FormsModule,
        ReactiveFormsModule,
        BrowserAnimationsModule,        // Material Angular
        MatStepperModule,               // Material Angular
        MatFormFieldModule,             // Material Angular
        MatInputModule,                 // Material Angular
        RouterModule.forRoot(appRoutes, routerOptions),
        NgxChartsModule,                // Charts
    
        // i18n
        HttpClientModule,
        TranslateModule.forRoot({
          loader: {
            provide: TranslateLoader,
            useFactory: HttpLoaderFactory,
            deps: [HttpClient]
          }
        })
      ],
      providers: [
        UserService,
        AuthGuard,
        NotAuthGuard,
        SurveyCompletedGuard,
        SurveyNotCompletedGuard,
        BankService,
        AuthService,
        ProductService
      ],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    

    感谢您的帮助,如果您需要更多信息,我很乐意为您提供。

    1 回复  |  直到 7 年前
        1
  •  4
  •   Llorenç Pujol Ferriol    7 年前

    “user.service”模块似乎有问题。你检查过这个文件被正确地推送到Gitlab远程服务器的分支主机吗? 如果是,请检查名称是否完全是“user.service”,而不是“user.service”。Gitlab计算机可能区分大小写。