angular - 从本地 Angular 库自动导入包括“public-api”并中断应用程序
问题描述
我有一个 Angular 7 库,我的应用程序将在项目文件夹中使用它。当我从编译的库中自动导入时,Visual Studio Code 在参考中使用公共 api 表面的路径,如下所示:
import { ModuleName } from '@org/lib/public-api';
这导致应用程序中出现编译错误:
ERROR in src/app/app.module.ts(9,28): Error during template compile of 'AppModule'
[2] Could not resolve @org/lib relative to [object Object]..
当我手动修复导入以删除“public-api”部分时,如下所示:
import { ModuleName } from '@org/lib';
该应用程序重新编译并且很好。我认为我没有更改任何默认配置。这就是我的 tsconfig 在工作区根目录中的样子,而我的库和应用程序 tsconfig 只是随附的开箱即用扩展ng generate
工作区tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"],
"paths": {
"@org/lib": ["dist/org-lib"],
"@org/lib/*": ["dist/org-lib/*"]
}
}
}
有没有人遇到过这个?
解决方案
如果以后有人遇到这个问题,可以通过查看如何为本地开发设置 Angular 项目来找到答案。除了他们的 public_api 文件,他们还有一个 index.ts
export * from './public_api';
这使您可以在开发期间在库之间进行交叉引用。
推荐阅读
- c# - Discord.NET 比较角色的更好方法
- angular - 在ionic 3中选择离子选择中的选项时如何打开另一个组件页面
- php - 我正在尝试上传多个图像并将每个路径存储在一个 id 但在 php mysql 的单独列中
- mysql - 选择不在 Yii CDbCriteria 中工作
- apache - Apache/XAMPP 不授予对子目录的访问权限
- javascript - 在 Vue 组件中继承 CSS
- wordpress - 私人客户页面的设置和自动填充
- android - simpledateformat 在实际时间上增加 30 分钟
- javascript - 试图理解范围和闭包
- javascript - 如何在浏览器(非移动设备)中显示本地 pdf 文件