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

Mas*_*erX 1 typescript server-side-rendering angular-universal angular

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

\n

我已经创建了自己的库,它是否以名称捆绑在 dist 文件夹中@asfc/shared

\n
ERROR in projects/asfc-web/src/environments/environment.ts:1:39 - error TS2307: Cannot find module '@asfc/shared' or its corresponding type declarations.\n\n1 import { PageNotFoundComponent } from '@asfc/shared';\n                                        ~~~~~~~~~~~~~~\n......\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

下面是我的,tsconfig.server.json

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

下面是我的 Dist Libs 结构,

\n
dist/asfc-shared\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 asfc-shared.d.ts\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.json\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 public_api.d.ts\n
Run Code Online (Sandbox Code Playgroud)\n

请帮忙。

\n

Dav*_*vid 5

尝试在您的中添加路径映射tsconfig.json

  "compilerOptions": {
    
    ....
    
    "paths": {
      "@asfc/shared/*": [
        "../../dist/asfc-shared/*"
      ],

    }
  },
Run Code Online (Sandbox Code Playgroud)

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