Angular 找不到我的自定义库的模块

Angular Cannot find module of my custom library

我在我的 angular 应用程序中实施 SSR,同时尝试 运行 npm run build:ssr 它抛出以下错误。

我创建了自己的库,它是否捆绑在名称为 @asfc/shared

的 dist 文件夹中
ERROR in projects/asfc-web/src/environments/environment.ts:1:39 - error TS2307: Cannot find module '@asfc/shared' or its corresponding type declarations.

1 import { PageNotFoundComponent } from '@asfc/shared';
                                        ~~~~~~~~~~~~~~
......

我已将 index.ts 添加到 files,但错误仍然没有消失

下面是我的,tsconfig.server.json

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "removeComments": false,
    "strict": false,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noImplicitAny": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "experimentalDecorators": true,
    "pretty": true,
    "declaration": true,
    "outDir": "../../dist/server",
    "lib": ["es2016", "DOM"],
    "types": [
      "node"
    ],
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "files": [
    "server.ts",
    "../../dist/asfc-shared/public_api.d.ts"
  ],
  "angularCompilerOptions": {
    "entryModule": "../../projects/asfc-web/src/app/app.server.module.ts#AppServerModule"
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

下面是我的 Dist Libs 结构,

dist/asfc-shared
    ├── asfc-shared.d.ts
    ├── package.json
    ├── public_api.d.ts

请帮忙。

尝试在 tsconfig.json

中添加路径映射
  "compilerOptions": {
    
    ....
    
    "paths": {
      "@asfc/shared/*": [
        "../../dist/asfc-shared/*"
      ],

    }
  },

您还从配置中排除了 dist 文件夹,但我猜这与包含您的库的文件夹不同。