目标:我有主应用程序和一个库。我需要能够使用主应用程序实时测试该库。换句话说,我需要能够构建我的库,并且主应用程序可以立即识别出一个更改(不想每次更改都推送到npm)。
错误:当我尝试使用以下设置运行主应用程序时,出现此错误。
StaticInjectorError(平台:核心)[PrmCompiler-> ComponentFactoryResolver]: NullInjectorError:ComponentFactoryResolver没有提供程序! ;区域:任务:Promise.then;值:错误: StaticInjectorError(AppModule)[PrmCompiler-> ComponentFactoryResolver]:
设置:我正在tsConfig中使用paths
来引用库
"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
设置为true。 (据说有几个地方都这样做了,但这是行不通的)
这是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
访问它时,这似乎才是问题。