我正在尋找使用this Yeoman generator作爲包含我可以發佈的幾個可重用表單組件的迷你項目的入門者。生成器生成一個模塊和一個配置爲使用的示例組件,指令,管道和服務(you can see the template files for the generator here)。無法將我本地開發的Angular模塊導入到Angular應用程序
然後,我使用npm link
允許我在我的Angular應用程序中安裝生成的項目,該項目看起來工作正常,如下面從項目的node_modules
目錄中所示;
我已經再導入模塊進入我的模塊我的角度應用程序中;
import { SampleModule } from 'my-test-library';
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
NgbModule,
MomentModule,
SampleModule // <-- Imported Here
],
declarations: [],
providers: []
})
export class TasksModule { }
該模塊的進口導致錯誤Uncaught Error: Unexpected value 'SampleModule' imported by the module 'TasksModule'
,我想不通爲什麼。
有兩兩件事比較我與其他第三方庫中導入庫時,我注意到(如ng-bootstrap
)
- 正如我已經使用
npm link
導入庫,讓我發展的整個過程中測試文件夾結構已導入(而不僅僅是dist
目錄。我認爲,這意味着非測距碼是由TasksModule
進口的。如果我試圖導入my-test-library/dist
我得到一個模塊不能被發現的錯誤。 - 不像
ng-bootstrap
我圖書館似乎缺少*.metadata.json
文件在輸出中。
我的圖書館的tsconfig.json
文件如下(持平發電機安裝)
{
"compilerOptions": {
"noImplicitAny": true,
"module": "commonjs",
"target": "ES5",
"emitDecoratorMetadata": true, <-- Checked to ensure this was true
"experimentalDecorators": true,
"sourceMap": true,
"declaration": true,
"outDir": "./dist"
},
"files": [
"typings/index.d.ts",
"index.ts"
],
"exclude": [
"node_modules",
"dist"
]
}
基於這些項目,或別的東西,我錯過什麼得到這個工作?謝謝!
編輯:。樣品* d.ts文件(如安裝後默認)
// sample.component.d.ts
export declare class SampleComponent {
constructor();
}
// sample.directive.d.ts
import { ElementRef } from '@angular/core';
export declare class SampleDirective {
private el;
constructor(el: ElementRef);
}
編輯2 所以,我想符號鏈接的dist
目錄(my-test-library/dist
)至node_modules
根,從那裏導入模塊,它工作正常。
- 有沒有辦法使用
npm link
只導入dist目錄(在根目錄下)? - 我也不明白爲什麼更新我的原始導入到
import { SampleModule } from 'my-test-library/dist';
不起作用?
你設置你的system.config文件映射''我的試驗library''的東西? – echonax
對不起,你不知道哪個文件是你的意思@echonax,我的項目沒有這個文件(它只有根級別文件顯示在上面的屏幕截圖) –
因此,你可能會遇到這個bug:https:// github.com/angular/angular/issues/11639這裏討論的是:https://github.com/angular/angular/issues/11438?如果是這樣,你可能會在9月16日找到'Avien'的答案。在第二個環節。我只是在這裏推測,因爲有這麼多的可能性。希望你能解決這個問題! – Dominik