从本地 Angular 库自动导入包括 "public-api" 并中断应用程序
Auto-importing from a local Angular library includes "public-api" and breaks application
我有一个 Angular 7 库供我的应用程序使用,它们都在项目文件夹中。当我从已编译库自动导入时,Visual Studio 代码使用参考中 public 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 在工作区根目录中的样子,我的库和应用程序 tsconfigs 只是 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';
这使您可以在开发过程中在库之间进行交叉引用。
我有一个 Angular 7 库供我的应用程序使用,它们都在项目文件夹中。当我从已编译库自动导入时,Visual Studio 代码使用参考中 public 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 在工作区根目录中的样子,我的库和应用程序 tsconfigs 只是 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';
这使您可以在开发过程中在库之间进行交叉引用。