I'm refactoring my Angular 11 application into libraries. My regular application is localized using @angular/localize
as a dev dependency, so I have made use of the $localize
directive in part of my code. I need to move this code with this directive into a library, but I can't figure out how to do this.
In my library's package.json
file, I've added a peer-dependency on @angular/localize
to match the devDependency in my application:
{
"name": "example",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^11.0.0",
"@angular/core": "^11.0.0",
"@angular/localize": "~11.0.0"
},
"dependencies": {
"tslib": "^2.0.0"
}
}
However the compiler reports that it can't find $localize
when I try to do ng build <library name>
.
× Compiling TypeScript sources through NGC
ERROR: projects/example/src/lib/example.service.ts:52:23 - error TS2304: Cannot find name '$localize'.
52 description = $localize `example localized text`;
~~~~~~~~~
How can I use the $localize
directive in my library?
>ng version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 11.0.1
Node: 12.18.3
OS: win32 x64
Angular: 11.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... localize, material, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1100.1
@angular-devkit/build-angular 0.1100.1
@angular-devkit/core 11.0.1
@angular-devkit/schematics 11.0.1
@angular/cli 11.0.1
@schematics/angular 11.0.1
@schematics/update 0.1100.1
ng-packagr 11.0.3
rxjs 6.6.3
typescript 4.0.5
Not sure, try to add this to your entry file: