[英]Angular builds fails only on github action
I have some angular tests, they all passes on my local machine.我有一些角度测试,它们都在我的本地机器上通过了。 The build is fine and the tests too.构建很好,测试也很好。
npm run build -- --configuration production
> project.net@0.0.0 build
> ng build --configuration production
Locale data for 'fr-FR' cannot be found. Using locale data for 'fr'.
✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.
Initial Chunk Files | Names | Raw Size | Estimated Transfer Size
main.40b9d18cea9debef.js | main | 1.04 MB | 225.81 kB
styles.39e0e34266a8723e.css | styles | 396.52 kB | 29.27 kB
scripts.2366f6834ae39e44.js | scripts | 377.25 kB | 120.49 kB
polyfills.c14262a5744a7a9b.js | polyfills | 34.29 kB | 11.07 kB
runtime.c12b062db9f7e4ff.js | runtime | 2.86 kB | 1.35 kB
| Initial Total | 1.83 MB | 387.98 kB
Lazy Chunk Files | Names | Raw Size | Estimated Transfer Size
900.f4e9f6038b59958d.js | Admin-admin-module | 783.02 kB | 140.25 kB
640.4608da492a45fac2.js | Admin-admin-module | 341.92 kB | 57.86 kB
Build at: 2022-12-16T14:06:14.821Z - Hash: 0efd680ede9213b8 - Time: 23625ms
But when it's running on github action I have errors, and I can't find why.但是当它在 github action 上运行时我有错误,我找不到原因。 I also don't know how to reproduce the error on my local machine.我也不知道如何在我的本地机器上重现错误。
Here is the github action file, which is for the test:这是github动作文件,用于测试:
name: Tests
on:
push:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Write env
run: >
touch ./src/environments/environment.ts &&
echo "export const environment = {" > ./src/environments/environment.ts &&
echo "production: false," >> ./src/environments/environment.ts &&
echo "domain_auth: 'http://localhost:8850'," >> ./src/environments/environment.ts &&
echo "domain_api: 'http://localhost:8851'" >> ./src/environments/environment.ts &&
echo "}" >> ./src/environments/environment.ts
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# caching node_modules
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
run: |
npm install
- name: Build
run: |
npm run build -- --configuration production
- name: Test
run: |
npm run test:prod
This action fail on the Build
step, here is the error:此操作在Build
步骤上失败,这是错误:
Run npm run build -- --configuration production
> project@0.0.0 build
> ng build --configuration production
Locale data for 'fr-FR' cannot be found. Using locale data for 'fr'.
- Generating browser application bundles (phase: setup)...
✔ Browser application bundle generation complete.
✔ Browser application bundle generation complete.
Warning: /home/runner/work/project-front/project-front/src/app/Services/session.service.ts depends on 'moment'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
./src/app/commons/commons.module.ts:32:0-67 - Error: Module not found: Error: Can't resolve './inputs/select/select.component' in '/home/runner/work/project-front/project-front/src/app/commons'
./src/app/commons/commons.module.ts:34:0-98 - Error: Module not found: Error: Can't resolve './cadre/cadre-comparaison/cadre-comparaison.component' in '/home/runner/work/project-front/project-front/src/app/commons'
./src/app/commons/commons.module.ts:35:0-101 - Error: Module not found: Error: Can't resolve './Button/bordure-fond-blanc/bordure-fond-blanc.component' in '/home/runner/work/project-front/project-front/src/app/commons'
./src/app/commons/commons.module.ts:36:0-95 - Error: Module not found: Error: Can't resolve './rating/basic-rating-bar/basic-rating-bar.component' in '/home/runner/work/project-front/project-front/src/app/commons'
./src/app/commons/commons.module.ts:37:0-94 - Error: Module not found: Error: Can't resolve './chevron/chevron-basique/chevron-basique.component' in '/home/runner/work/project-front/project-front/src/app/commons'
Error: src/app/Admin/admin.module.ts:154:5 - error NG6002: 'CommonsModule' does not appear to be an NgModule class.
154 CommonsModule,
~~~~~~~~~~~~~
src/app/commons/commons.module.ts:100:14
100 export class CommonsModule {
~~~~~~~~~~~~~
Is it missing an @NgModule annotation?
The error seems to be on my CommonsModule, but it's working fine on my local machine:错误似乎出在我的 CommonsModule 上,但它在我的本地机器上运行良好:
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {ClipboardComponent} from './components/clipboard/clipboard.component';
import {FontAwesomeModule} from '@fortawesome/angular-fontawesome';
import {TooltipModule} from 'primeng/tooltip';
import {ColorPickerComponent} from './components/inputs/color-picker/color-picker.component';
import {InputComponent} from './components/inputs/input/input.component';
import {InputTextModule} from 'primeng/inputtext';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {PasswordModule} from 'primeng/password';
import {InputMaskModule} from 'primeng/inputmask';
import {InputTextareaModule} from 'primeng/inputtextarea';
import {SwitchComponent} from './components/inputs/switch/switch.component';
import {InputSwitchModule} from 'primeng/inputswitch';
import {BandeauPromoComponent} from './components/header/bandeau-promo/bandeau-promo.component';
import {SurnavbarComponent} from './components/surnavbar/surnavbar.component';
import {SurnavbarRatingComponent} from './components/surnavbar/surnavbar-rating/surnavbar-rating.component';
import {SurnavbarButtonComponent} from './components/surnavbar/surnavbar-button/surnavbar-button.component';
import { CheckboxInputComponent } from './inputs/checkbox-input/checkbox-input.component';
import { CheckboxModule } from 'primeng/checkbox';
import { ReturnButtonComponent } from './components/return-button/return-button.component';
import { RouterModule } from '@angular/router';
import {PdfViewerComponent} from './components/pdf-viewer/pdf-viewer.component';
import {NgxExtendedPdfViewerModule} from 'ngx-extended-pdf-viewer';
import {SkeletonModule} from 'primeng/skeleton';
import {ButtonModule} from 'primeng/button';
import {SaveFormDirective} from '../Directives/save-form.directive';
import { ModalFormComponent } from './components/modal-form/modal-form.component';
import { EncartComponent } from './components/encart/encart.component';
import {SafeHtmlPipe} from '../Pipes/safe-html.pipe';
import {SelectComponent} from './inputs/select/select.component';
import {DropdownModule} from 'primeng/dropdown';
import {CadreComparaisonComponent} from './cadre/cadre-comparaison/cadre-comparaison.component';
import {BordureFondBlancComponent} from './Button/bordure-fond-blanc/bordure-fond-blanc.component';
import {BasicRatingBarComponent} from './rating/basic-rating-bar/basic-rating-bar.component';
import {ChevronBasiqueComponent} from './chevron/chevron-basique/chevron-basique.component';
@NgModule({
declarations: [
ClipboardComponent,
ColorPickerComponent,
InputComponent,
SwitchComponent,
BandeauPromoComponent,
SurnavbarComponent,
SurnavbarRatingComponent,
SurnavbarButtonComponent,
CheckboxInputComponent,
ReturnButtonComponent,
SaveFormDirective,
ModalFormComponent,
EncartComponent,
SafeHtmlPipe,
PdfViewerComponent,
SelectComponent,
CadreComparaisonComponent,
BordureFondBlancComponent,
BasicRatingBarComponent,
ChevronBasiqueComponent,
],
exports: [
ClipboardComponent,
ColorPickerComponent,
InputComponent,
SwitchComponent,
BandeauPromoComponent,
SurnavbarComponent,
CheckboxInputComponent,
ReturnButtonComponent,
SelectComponent,
SaveFormDirective,
EncartComponent,
PdfViewerComponent,
ClipboardComponent,
CadreComparaisonComponent,
BordureFondBlancComponent,
BasicRatingBarComponent,
ChevronBasiqueComponent
],
imports: [
CommonModule,
FontAwesomeModule,
TooltipModule,
InputTextModule,
ReactiveFormsModule,
PasswordModule,
InputMaskModule,
InputTextareaModule,
FormsModule,
CheckboxModule,
RouterModule,
DropdownModule,
InputSwitchModule,
SkeletonModule,
ButtonModule,
NgxExtendedPdfViewerModule,
]
})
export class CommonsModule {
}
I tried to delete my loca node_modules
then re-install it and re run the build but still no error on my local computer.我试图删除我的 loca node_modules
然后重新安装它并重新运行构建但在我的本地计算机上仍然没有错误。 I also deleted the node_modules
cache on github action and re-runned the action, still the same error.我也删除了github动作上的node_modules
缓存,重新运行动作,还是一样的错误。
What could cause this error, but only on github action?什么可能导致此错误,但仅限于 github 操作?
I managed to fix the errors, but I am not sure why.我设法修复了错误,但不确定原因。
On the github pull request I could see two folder "Commons" and "commons".在 github pull request 上,我可以看到两个文件夹“Commons”和“commons”。 But locally I only have one directory:但是在本地我只有一个目录:
I think the problem happened because we were two developers working on similar parts, we both created a commons module, but one with a capital "C".我认为问题的发生是因为我们是两个从事相似部分工作的开发人员,我们都创建了一个公共模块,但其中一个带有大写“C”。 When we merged our work we kept only one directory.当我们合并我们的工作时,我们只保留一个目录。 But I don't know why github kept the location of some components inside the other directory.但是我不知道为什么github将某些组件的位置保留在其他目录中。
To fix this:要解决此问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.