目标:我有主应用程序和一个库。我需要能够使用主应用程序实时测试该库。换句话说,我需要能够构建我的库并且主应用程序可以立即识别更改(不想每次更改都推送到 npm)。
错误当我尝试使用以下设置运行主应用程序时,我收到此错误。
StaticInjectorError(Platform: core)[PrmCompiler -> ComponentFactoryResolver]: NullInjectorError: No provider for ComponentFactoryResolver!; 区域:; 任务:Promise.then;值:错误:StaticInjectorError(AppModule)[PrmCompiler -> ComponentFactoryResolver]:
设置:我paths
在 tsConfig 中使用来引用库
"compilerOptions": {
"typeRoots": [
"node_modules/@types"
],
"paths": {
"@stud/myLibrary": ["../librarys/dist/MyLibrary"],
}
}
prod: true
我使用和构建库aot: true
这是库中的 tsconfig.lib.ts。
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"module": "es2015",
"rootDir": "src",
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"inlineSources": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"types": [],
"lib": [
"dom",
"es2015"
]
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"flatModuleId": "AUTOGENERATED",
"flatModuleOutFile": "AUTOGENERATED",
"preserveSymlinks": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts",
"**/*.stubs.ts"
]
}
我已经preserveSymlinks
设置为真。(有几个地方说要这样做,但它不起作用)
这是 lib 的 angular.json。
"myLibrary": {
"root": "projects/myLibrary",
"sourceRoot": "projects/myLibrary/src",
"projectType": "library",
"prefix": "prm",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/myLibrary/tsconfig.lib.json",
"project": "projects/myLibrary/ng-package.json"
},
"configurations": {
"production": {
"project": "projects/myLibrary/ng-package.prod.json"
}
}
},
....
}
如果我发布应用程序,它工作正常,如果我尝试使用paths
.