Angular9 νλ‘μ νΈμμμ΄ μ€λ₯κ° λ°μνμ΅λλ€.
ERROR in Invalid provider for LazyLoadImageHooks. useClass cannot be undefined.
Usually it happens when:
1. There's a circular dependency (might be caused by using index.ts (barrel) files).
2. Class was used before it was declared. Use forwardRef in this case.
μ¬κΈ°μ κ°μ λ¬Έμ
λλ κ°μ λ¬Έμ κ° λ°μν©λλ€.
λꡬλ μ§ λμΈ μ μμ΅λκΉ?
λλ κ°μ λ¬Έμ κ° μκ²Όμ΄ .... λμ μ€
μ ... μμ νκΈ° μ κΉμ§ λ²μ 7.1.0μΌλ‘ μ¬μ©νκ³ μμ΅λλ€.
μ¬μ©μ€μΈ ng-lazyload-image
λ²μ ( npm ls ng-lazyload-image
μ€ννμ¬ νμΈ)
λΉλ μκ° λλ λΈλΌμ°μ μ½μμμμ΄ μ€λ₯κ° λ°μν©λκΉ?
μ΄ λ¬Έμ λ‘ μμ μ μ₯μλ₯Ό λ§λ€ μ μμ΅λκΉ? https://github.com/tjoskar/ng-lazyload-image/blob/master/example/package.json μμ ν΄λμμ Angular 9λ₯Ό μ¬μ©νκ³ μλλ° κ±°κΈ°μμ λ¬Έμ λ₯Ό λ³Ό μ μμ΅λκΉ? μ΄ μ½λ μλ λ°μ€μλ ν¬ν¨λμ§ μμ΅λλ€ : https://codesandbox.io/s/lazy-load-image-with-httpclient-to538?file=/src/app/app.module.ts (μ :)
@tjoskar μ΄ μ€λ₯λ λΉλμ λ°μνμ΅λλ€.
μ€λ₯ : LazyLoadImageHooksμ λν μλͺ»λ 곡κΈμμ
λλ€. useClassλ μ μ ν΄μ ν μ μμ΅λλ€.
μΌλ°μ μΌλ‘ λ€μκ³Ό κ°μ κ²½μ°μ λ°μν©λλ€.
1. μν μ’
μμ±μ΄ μμ΅λλ€ (index.ts (λ°°λ΄) νμΌμ μ¬μ©νμ¬ λ°μν μ μμ).
2. ν΄λμ€κ° μ μΈλκΈ° μ μ μ¬μ©λμμ΅λλ€. μ΄ κ²½μ° forwardRefλ₯Ό μ¬μ©νμμμ€.
μ²λ¦¬λμ§ μμ μμΈκ° λ°μνμ΅λλ€. LazyLoadImageHooksμ λν μλͺ»λ 곡κΈμμ
λλ€. useClassλ μ μ ν΄μ ν μ μμ΅λλ€.
μΌλ°μ μΌλ‘ λ€μκ³Ό κ°μ κ²½μ°μ λ°μν©λλ€.
1. μν μ’
μμ±μ΄ μμ΅λλ€ (index.ts (λ°°λ΄) νμΌμ μ¬μ©νμ¬ λ°μν μ μμ).
2. ν΄λμ€κ° μ μΈλκΈ° μ μ μ¬μ©λμμ΅λλ€. μ΄ κ²½μ° forwardRefλ₯Ό μ¬μ©νμμμ€.
κ°λ λΌμ΄λΈλ¬λ¦¬λ₯Ό λ§λλ λμμ΄ μ€λ₯κ° λ°μνμ΅λλ€.
λ²μ 7μμλ λ°μνμ§ μμ΅λλ€.
λλ μ΄κ²μ μ¬ν ν μ μμ΅λλ€. λ°©κΈ μλ‘μ΄ μ΅κ·€λ¬ 9 μ± (9.1.9)μ λ§λ€μμ΅λλ€.
β― ng new my-app
β― npm ls @angular/core
[email protected]
βββ @angular/[email protected]
κ·Έλ° λ€μ λ€μκ³Ό κ°μ΄ λ³κ²½νμ΅λλ€. https://github.com/tjoskar/ng-lazyload-image-bugs/commit/7fe50bd1631a20e7bcfed82f2a34acaeb6b50533
κ·Έλ¦¬κ³ μ무 λ¬Έμ μμ΄ npm run build
( ng build
)λ₯Ό μ€νν©λλ€.
μ΄ λ¬Έμ λ₯Ό ν΄κ²°νλ €λ©΄ κ·νμ λμμ΄ νμν©λλ€.
LazyLoadImageModule
λ€μνμμ NgModule
?μμ© νλ‘κ·Έλ¨μ λ§λ€μ§ λ§κ³ λΌμ΄λΈλ¬λ¦¬λ₯Ό λ§λμμμ€.
μ΄ μ¬μ μ¬μ©
https://angular.io/guide/creating-libraries
λͺ¨λμ κ°μ Έ μμ npmμμ ν΄μ νμμμ€.
@ emanuele-galeotti, λλ λ°λ₯΄μ§ μμ΅λλ€. ng-lazyload-image
λ λΌμ΄λΈλ¬λ¦¬μ΄λ©° npmμ κ²μλ©λλ€. μμ© νλ‘κ·Έλ¨μμ ng-lazyload-image
μ μ¬μ©νκ³ μλ€λ μΈμμ λ°μμΌλ―λ‘ μμ© νλ‘κ·Έλ¨μ λ§λ€κ³ λΌμ΄λΈλ¬λ¦¬ ( ng-lazyload-image
)λ₯Ό κ°μ Έ μμ΅λλ€.
λΌμ΄λΈλ¬λ¦¬λ₯Ό λ§λ€κ³ μμΌλ©° ng-lazyload-image
λ₯Ό μ’
μμ±μΌλ‘ μ¬μ©νκ³ μΆλ€κ³ λ§μνμλκΉ? μλλ©΄ λ§ν¬ ν κ°μ΄λμ λ°λΌ μ λΌμ΄λΈλ¬λ¦¬λ₯Ό λ§λ€κ³ μ½λλ₯Ό μλ‘ λ§λ λΌμ΄λΈλ¬λ¦¬λ‘ λ§μ΄κ·Έλ μ΄μ
ν΄μΌνλ€κ³ μ μν©λκΉ?
μμ μ€λ₯λ λ€μκ³Ό κ°μ κ²½μ°μ λ°μν©λλ€.
μ΄ μμ
μ μμ²ν μ μμ΅λκΉ?
νλ‘μ νΈκ° λΉκ³΅κ°μ΄κΈ° λλ¬Έμ μ μ₯μκ° μμ΅λλ€.
λΌμ΄λΈλ¬λ¦¬λ₯Ό λΉλ ν λ λλ λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©νλ μ ν리μΌμ΄μ μ λΉλ ν λ λΉλκ° μ€ν¨ν©λκΉ?
μ΄μ λ€μμ μννμ΅λλ€.
β― ng new my-workspace --create-application=false
CREATE my-workspace/README.md (1028 bytes)
CREATE my-workspace/.editorconfig (274 bytes)
CREATE my-workspace/.gitignore (631 bytes)
CREATE my-workspace/angular.json (136 bytes)
CREATE my-workspace/package.json (1196 bytes)
CREATE my-workspace/tsconfig.json (489 bytes)
CREATE my-workspace/tslint.json (2933 bytes)
β Packages installed successfully.
β― ng generate library my-lib
CREATE projects/my-lib/README.md (986 bytes)
CREATE projects/my-lib/karma.conf.js (1022 bytes)
CREATE projects/my-lib/ng-package.json (155 bytes)
CREATE projects/my-lib/package.json (184 bytes)
CREATE projects/my-lib/tsconfig.lib.json (435 bytes)
CREATE projects/my-lib/tsconfig.lib.prod.json (97 bytes)
CREATE projects/my-lib/tsconfig.spec.json (246 bytes)
CREATE projects/my-lib/tslint.json (247 bytes)
CREATE projects/my-lib/src/public-api.ts (155 bytes)
CREATE projects/my-lib/src/test.ts (781 bytes)
CREATE projects/my-lib/src/lib/my-lib.module.ts (222 bytes)
CREATE projects/my-lib/src/lib/my-lib.component.spec.ts (622 bytes)
CREATE projects/my-lib/src/lib/my-lib.component.ts (264 bytes)
CREATE projects/my-lib/src/lib/my-lib.service.spec.ts (353 bytes)
CREATE projects/my-lib/src/lib/my-lib.service.ts (134 bytes)
UPDATE angular.json (1383 bytes)
UPDATE package.json (1360 bytes)
UPDATE tsconfig.json (588 bytes)
β Packages installed successfully.
β― cd projects/my-lib
β― npm install ng-lazyload-image -D
+ [email protected]
added 1 package from 1 contributor and audited 1 package in 1.034s
found 0 vulnerabilities
# I made the following changes: https://github.com/tjoskar/ng-lazyload-image-bugs/commit/1bf60bcbf6133751c41f52cd3d837614dfb60bd0
β― cd ../..
β― ng build my-lib
Building Angular Package
******************************************************************************
It is not recommended to publish Ivy libraries to NPM repositories.
Read more here: https://v9.angular.io/guide/ivy#maintaining-library-compatibility
******************************************************************************
------------------------------------------------------------------------------
Building entry point 'my-lib'
------------------------------------------------------------------------------
Compiling TypeScript sources through ngc
Bundling to FESM2015
Bundling to FESM5
Bundling to UMD
WARNING: No name was provided for external module 'ng-lazyload-image' in output.globals β guessing 'ngLazyloadImage'
Minifying UMD bundle
Writing package metadata
Removing devDependencies section in package.json.
Built my-lib
------------------------------------------------------------------------------
Built Angular Package
- from: ng-lazyload-image-bugs/463-invalid-provider-for-lazyLoadImageHook-libs/projects/my-lib
- to: ng-lazyload-image-bugs/463-invalid-provider-for-lazyLoadImageHook-libs/dist/my-lib
------------------------------------------------------------------------------
λΌμ΄λΈλ¬λ¦¬κ° μμ΅λλ€ : https://github.com/tjoskar/ng-lazyload-image-bugs/tree/master/463-invalid-provider-for-lazyLoadImageHook-libs
κ·Έλ¦¬κ³ μ¬κΈ°μ λ΄κ° λ³κ²½ ν λ΄μ©μ λλ€ : https://github.com/tjoskar/ng-lazyload-image-bugs/commit/1bf60bcbf6133751c41f52cd3d837614dfb60bd0
νλ‘μ νΈκ° λΉκ³΅κ°μ΄κ³ μ½λλ₯Ό 곡μ ν μ μλμ§ μ΄ν΄νμ§λ§ μ€λ₯λ₯Ό μ¬ν ν μμλ μμ νλ‘μ νΈλ₯Ό λ§λ€ μ μλ€λ©΄ λμμ΄ λ κ²μ λλ€.
λΌμ΄λΈλ¬λ¦¬λ₯Ό λΉλ ν λ μ½λλ₯Ό 곡μ ν μμλ μ¦μ μ€ν¨ν©λλ€.
λλ κ°μ λ¬Έμ κ° :(. λλ LAZY LOAD MODULEλ₯Ό μμ λͺ¨λμ μΆκ°νμ΅λλ€.
Ionic 5, angular 9 μ¬μ©. μ νμ λΉλλ₯Ό μλνλ©΄ μ€λ₯κ° λ°μνμ΅λλ€.
κ°μ λ¬Έμ . ionic 5 λ° andular 9λ‘ μ± λΉλλ₯Ό μλνμμμ€ ...
μ΄μ λ²μ μΌλ‘ λμκ°μ μ»΄νμΌ ν μ μμ΅λλ€.
npm install [email protected]
Ionic 5.0.7 / Angular 8.2.14λ₯Ό μ¬μ© μ€μ
λλ€.
μ΄μ λ²μ μΌλ‘ λμκ°μ μ»΄νμΌ ν μ μμ΅λλ€.
npm install [email protected]
Ionic 5.0.7 / Angular 8.2.14λ₯Ό μ¬μ© μ€μ λλ€.
λμ΄μ .. κ°μ¬ν©λλ€ ....
@ Davei234 μ μλν©λλ€.
λλ μ΄κ²μ μ¬ν ν μ μκΈ° λλ¬Έμ μ΄κ²μ μ¬ννλ νλ‘μ νΈλ₯Ό λꡬλ λ§λ€ μ μλ€λ©΄ κΈ°μ κ²μ
λλ€.
λλ μ΄κ²μ μ¬ννλ €κ³ λͺ κ°μ§ λ€λ₯Έ νλ‘μ νΈλ₯Ό λ§λ€μμ΅λλ€.
ng-lazyload-image
κ°μ Έ μ€κΈ° : https://github.com/tjoskar/ng-lazyload-image-bugs/tree/master/463-invalid-provider-for-lazyLoadImageHooks-sub-moduleng-lazyload-image
κ°μ Έ μ€κΈ° : https://github.com/tjoskar/ng-lazyload-image-bugs/commit/39b93c932ac02788cb1f92cebe1c05fb7d1f4e71μ΄κ²μ μ¬ννλ μ½λλ₯Ό 곡μ ν μμλ μ¬λμ΄ μμΌλ©΄ μλ €μ£ΌμΈμ.
Ivy
νμ±νλμ΄ μμ΅λκΉ? ng version
λ₯Ό μ€ννμ¬ νμΈν μ μμ΅λλ€. λΉνμ±ν ν κ²½μ° λΉνμ±ν ν μ΄μ κ° μμ΅λκΉ? μλλ©΄ νμ±ννκΈ° μν΄ ν
μ€νΈ ν μ μμ΅λκΉ? λλ νμ€ν κ·Έλ κ² λ§ νμΈνλ λ°©λ²μ λͺ¨λ₯΄κ² μ΄μ enableIvy
λΉμ μ tsconfig.sjonκ³Ό tsconfig.app.json
νμΌ.
Ivy
νμ±νλμ΄ μμ΅λκΉ?ng version
λ₯Ό μ€ννμ¬ νμΈν μ μμ΅λλ€. λΉνμ±ν ν κ²½μ° λΉνμ±ν ν μ΄μ κ° μμ΅λκΉ? μλλ©΄ νμ±ννκΈ° μν΄ ν μ€νΈ ν μ μμ΅λκΉ? λλ νμ€ν κ·Έλ κ² λ§ νμΈνλ λ°©λ²μ λͺ¨λ₯΄κ² μ΄μenableIvy
λΉμ μ tsconfig.sjonκ³Όtsconfig.app.json
νμΌ.
UI λΌμ΄λΈλ¬λ¦¬λ₯Ό κ΅¬μΆ μ€μ λλ€. npmμμ νμ©νμ§ μκΈ° λλ¬Έμ μμ΄λΉκ° μμ΅λλ€.
8.0.1
λ²μ μ ivyμμλ§ μλνλ κ² κ°μ΅λλ€. κ·Έλ¬λ μ§κΈμ μ κ·Έλ°μ§ λͺ¨λ₯΄κ² μ΅λλ€.
IVYλ₯Ό λΉνμ±ννμ λ angular 9μμ λμΌν λ¬Έμ κ° λ°μνμ΅λλ€.
μλ νμΈμ. node_modules λ° lock νμΌμ μμ νκ³ npm install λ° λΉλλ₯Ό λ€μ μ€ννλ©΄ λ¬Έμ κ° λ°μνμ΅λλ€.
μ΄ μ μλ λͺ¨λ κ²μ΄ μ΅μ 8.0.1μμ μ μλνμ΅λλ€.
μμ΄λΉκ° νμ±νλ©λλ€.
μ΄μ λ²μ (7.1.0)μΌλ‘ λμκ°μ λ€μ μλν©λλ€.
λλ κ°μ λ¬Έμ κ° μμΌλ©° Ivyλ₯Ό νμ±ννμ΅λλ€.
Angular 9λ₯Ό μ€ννλ λμ λ²μ 7.1.0μ μ¬μ©νμ¬ μλνμ§λ§ μ΄μ Angular 10μ΄ λμμΌλ―λ‘ λ μ΄μ μλνμ§ μμ΅λλ€.
λ²μ 7μ "ModuleWithProviders"λ₯Ό μ¬μ©ν©λλ€. Angular 10μμ λ³κ²½λ
static forRoot(options: ModuleOptions): ModuleWithProviders;
μ€λ₯ λ°μ
ERROR in Invalid provider for LazyLoadImageHooks. useClass cannot be undefined.
Usually it happens when:
1. There's a circular dependency (might be caused by using index.ts (barrel) files).
2. Class was used before it was declared. Use forwardRef in this case.
μμ€ μΈμ΄ νμΌμ μΆμΆνλ €κ³ ν λ κ°λ 10μ μ¬μ©νλ κ²κ³Ό λμΌν μ€λ₯κ° λ°μν©λλ€.
ng xi18n --format=xlf2 --output-path src/locales
μ€λ₯:
ERROR in Invalid provider for LazyLoadImageHooks. useClass cannot be undefined.
Usually it happens when:
1. There's a circular dependency (might be caused by using index.ts (barrel) files).
2. Class was used before it was declared. Use forwardRef in this case.
Ivyλ₯Ό λΉνμ±ν ν λλ§ μ΄κ²μ μ¬ν ν μ μμ΅λλ€. Angular 10 μ±μ λ§λ€μμ§ λ§ Ivy
λΉνμ±ννμ λλ§ μ€λ₯κ° λ°μνμ΅λλ€.
λλ μ΄μ Ivyμ ν¨κ» μλνλ κ²μ²λΌ 보μ΄λ μ λ²μ μ κ²μνμ΅λλ€. μλν΄λ³΄κ³ ν¨κ³Όκ° μλμ§ νμΈνμμμ€ : npm install [email protected]
.
μ¬μ©μ μ§μ νν¬λ₯Ό μ¬μ©νλ κ²½μ° μ½λλ₯Ό μ
λ°μ΄νΈν΄μΌν©λλ€.
μ μ:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LazyLoadImageModule, IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';
import { AppComponent } from './app.component';
class LazyLoadImageHooks extends IntersectionObserverHooks {
async loadImage({ imagePath }: Attributes): Promise<string> {
return await fetch(imagePath, {
headers: {
Authorization: 'Bearer ...',
},
})
.then((res) => res.blob())
.then((blob) => URL.createObjectURL(blob));
}
}
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, LazyLoadImageModule.forRoot(LazyLoadImageHooks)],
bootstrap: [AppComponent],
})
export class MyAppModule {}
ν:
import { NgModule, Injectable } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LazyLoadImageModule, IntersectionObserverHooks, Attributes, LAZYLOAD_IMAGE_HOOKS } from 'ng-lazyload-image';
import { AppComponent } from './app.component';
@Injectable()
export class LazyLoadImageHooks extends IntersectionObserverHooks {
async loadImage({ imagePath }: Attributes): Promise<string> {
return await fetch(imagePath, {
headers: {
Authorization: 'Bearer ...',
},
})
.then((res) => res.blob())
.then((blob) => URL.createObjectURL(blob));
}
}
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, LazyLoadImageModule],
providers: [{ provide: LAZYLOAD_IMAGE_HOOKS, useClass: LazyLoadImageHooks }],
bootstrap: [AppComponent],
})
export class MyAppModule {}
ivyκ°μλ angular 10 μ±μμμ΄ μ€λ₯κ° νμλ©λλ€. κ·Έλ¬λ μ»΄νμΌμ μ μμ μΌλ‘ μλνμ§λ§ ng xi18n
λͺ
λ Ή
8.0.2-21
μ
κ·Έλ μ΄λνλ κ²μ΄ λμμ΄λμμ΅λλ€.
Angular 10
[email protected]
providers: [{ provide: 'LazyLoadImageHooks', useClass: LazyLoadImageHooks }]
μλνλ€
λ²μ 9.0.0μμ μμ λμ΄μΌν©λλ€.
κ°μ₯ μ μ©ν λκΈ
μ΄μ λ²μ μΌλ‘ λμκ°μ μ»΄νμΌ ν μ μμ΅λλ€.
npm install [email protected]
Ionic 5.0.7 / Angular 8.2.14λ₯Ό μ¬μ© μ€μ λλ€.