Angular 6/7 使用自定义库会引​​发错误 TS2397:找不到模块“*”

Lin*_*der 6 typescript angular

我目前正在尝试将我的 Angular 2.something 项目升级到最新版本。我有一个自定义的 angular.config 文件,因此我可以构建 2 个使用相同组件“库”的应用程序。但随后 Angular 6 的史诗版本发布了真正的 Angular 库!但是现在我被困(再次)试图将我的项目重构为这个新版本。

我已经将组件库(名为“核心”)构建到 DIST 文件夹中。甚至 Typescript 也可以使用这个库。但是当我尝试构建我的网络应用程序 Angular CLI 时,它开始抱怨它找不到模块“核心”。

以下代码片段是文件夹 dist/core 中的 public_api.d.ts:

export { WdCoreModule } from './lib/wd-core.module';
export { wdApi } from './lib/core/wd.service';
export { ProcessTokenComponent } from './lib/core/process-token.component';
export { GroupByPipe } from './lib/core/group-by.pipe';
export { AvatarComponent } from './lib/avatar/avatar.component';
export { GameElementsModule } from './lib/game-elements/game-elements.module';
export { AchievementsComponent } from './lib/game-elements/achievements/achievements.component';
export { ModalComponentComponent } from './lib/modal-component/modal-component.component';
export { BaseModalService, BaseModalComponent } from './lib/core/basemodal.service';
export { NavMenuComponent } from './lib/nav-menu/nav-menu.component';
.... More exports ahead
Run Code Online (Sandbox Code Playgroud)

我在 tsconfig.json 中添加了这个库的路径

"paths": {
      "core": [
        "dist/core"
      ],
      "core/*": [
        "dist/core/*"
      ],
}
Run Code Online (Sandbox Code Playgroud)

然后是时候将库“core”中的模块和组件导入到名为“cms”的应用程序中了。

import { WdCoreModule } from 'core';
Run Code Online (Sandbox Code Playgroud)

还没有错误!现在我已准备好构建我的项目:ng serve cms 这将引发以下错误:

项目/cms/src/app/app.module.ts(52,30): 错误 TS2307: 找不到模块“核心”。

我一直在寻找解决这个问题的方法,但我有点卡住了。任何编码英雄可以帮助我?

编辑:解决方案的额外信息

我按照以下帖子打包并安装我的构建库

https://blog.angularindepth.com/creating-a-library-in-angular-6-part-2-6e2bc1e14121

以下 2 个命令对我有用:

//package.json
"npm_pack": "cd dist/core && npm pack",
//then
npm install dist/core/core-0.0.1.tgz --save
Run Code Online (Sandbox Code Playgroud)

Mik*_*One 5

您应该在packages.json 中链接您的构建库(.tgz)。ts.config 路径仅用于开发时间..