Angular 角度库,找不到名称$localize
我正在使用Nx工具将Angular 11应用程序重构为库。我的主应用程序将Angular 角度库,找不到名称$localize,angular,localization,internationalization,nrwl,nomachine-nx,Angular,Localization,Internationalization,Nrwl,Nomachine Nx,我正在使用Nx工具将Angular 11应用程序重构为库。我的主应用程序将@angular/localize作为依赖项,并将@angular/localize导入polyfills.ts。在我的库代码中每次使用$localize都会生成Typescript错误TS2304:找不到名称“$localize”。我的库没有自己的package.json文件。应用程序构建工作正常。这看起来像是打字问题。有什么想法吗 库tsconfig.lib.json { "extends":
@angular/localize
作为依赖项,并将@angular/localize
导入polyfills.ts
。在我的库代码中每次使用$localize
都会生成Typescript错误TS2304:找不到名称“$localize”
。我的库没有自己的package.json
文件。应用程序构建工作正常。这看起来像是打字问题。有什么想法吗
库tsconfig.lib.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"target": "es2015",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
],
"include": [
"**/*.ts"
]
}
库中的tsconfig.json
{
"extends": "../../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
角度版本
Angular CLI: 11.1.1
Node: 14.15.4
OS: win32 x64
Angular: 11.1.0
... animations, cdk, common, compiler, compiler-cli, core
... elements, forms, language-service, localize, material
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: <error>
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1002.1
@angular-devkit/build-angular 0.1101.1
@angular-devkit/core 10.2.1
@angular-devkit/schematics 11.0.7
@angular/cli 11.1.1
@schematics/angular 11.0.7
@schematics/update 0.1101.1
rxjs 6.6.3
typescript 4.1.3
角度CLI:11.1.1
节点:14.15.4
操作系统:win32 x64
角度:11.1.0
... 动画、cdk、通用、编译器、编译器cli、核心
... 元素、形式、语言服务、本地化、材料
... 平台浏览器,平台浏览器动态,路由器
常春藤工作区:
软件包版本
---------------------------------------------------------
@角度devkit/architect 0.1002.1
@角度开发套件/构建角度0.1101.1
@角度devkit/核心10.2.1
@角度devkit/示意图11.0.7
@angular/cli 11.1.1
@示意图/角度11.0.7
@示意图/更新0.1101.1
rxjs 6.6.3
打字稿4.1.3
导入@angular/localize/init可能会导致tslint错误,因为它会添加到全局上下文中(即,产生副作用)。要修复此错误,请将以下内容添加到tslint.config “无进口副作用”:[ 符合事实的 { “忽略模块”:“(core js/.| zone\.js/.|@angular/localize/init)$” }
]我也遇到了同样的问题,我在
polyfills的第一行添加了以下代码。ts
解决了我的问题
import '@angular/localize/init';
你是如何解决这个问题的?下面的解决方案对我不起作用。我必须添加
import'@angular/localize/init'在mytest setup.ts
文件中的code>以运行测试。导入import'/polyfills'后运行生成代码>在myindex.ts
中。也许这能帮助你找到解决问题的方法,即使我的问题和你的不完全一样。