我在创建hello世界图书馆项目并通过从本地注册表中安装npm来使用它方面遇到问题。
我在我的图书馆用户应用程序中不断收到此错误消息:
ERROR in src/app/app.module.ts(4,31): error TS2307: Cannot find module 'ng-test-lib'.
将库包安装到nodemodules文件夹中就好了。这是一个屏幕截图:
这是npm软件包中捆绑的package.json的内容:
{
"_from": "ng-test-lib@prerelease",
"_id": "ng-test-lib@0.0.0-b20180829144257",
"_inBundle": false,
"_integrity": "sha512-9oOX6tB+HdvHfOWVbv8fFEC3WpxPd7nvHn6bBMAGlPP6/2RumidYFQLYCSdSE+w7pjF96PippgTBK8DUxkxEMw==",
"_location": "/ng-test-lib",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "ng-test-lib@prerelease",
"name": "ng-test-lib",
"escapedName": "ng-test-lib",
"rawSpec": "prerelease",
"saveSpec": null,
"fetchSpec": "prerelease"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "http://nexus/content/groups/alm_public_read_npm/ng-test-lib/-/ng-test-lib-0.0.0-b20180829144257.tgz",
"_shasum": "c3de3039fe37908292834d4edac893a8f118a28f",
"_spec": "ng-test-lib@prerelease",
"_where": "C:\\lib-client",
"bundleDependencies": false,
"deprecated": false,
"name": "ng-test-lib",
"peerDependencies": {
"@angular/common": "^6.0.0-rc.0 || ^6.0.0",
"@angular/core": "^6.0.0-rc.0 || ^6.0.0"
},
"version": "0.0.0-b20180829144257"
}
这是我尝试导入的方式:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import {NgTestLibModule} from 'ng-test-lib';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
NgTestLibModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
关于如何在这里解决问题的任何指示?该库本身只是一个hello世界库,没有任何外部依赖项或任何东西,只是试图证明目前的路径。
谢谢!
----编辑
所以看起来像在projects / ng-test-lib / package.json中指定一个主要属性解决了我的问题,但是我的问题是为什么Angular的库脚手架为什么不将主要属性添加到package.json文件中呢?图书馆?
添加
{
"name": "ng-test-lib",
"version": "0.0.1",
"main":"fesm2015/ng-test-lib.js",
"peerDependencies": {
"@angular/common": "^6.0.0-rc.0 || ^6.0.0",
"@angular/core": "^6.0.0-rc.0 || ^6.0.0"
}
}
添加main属性对我来说是不好的做法吗?