Angular 7 通用 - 无法解析路径

Angular 7 Universal - Could not resolve paths

我使用 Angular Universal 学习了这个关于服务器端渲染的精彩教程 https://angularfirebase.com/lessons/server-side-rendering-firebase-angular-universal/

但是当 运行 npm run build:ssr && npm run serve:ssr 时,我得到以下错误:

不知何故,它无法识别我在 tsconfig.json 文件中定义的路径。

tsconfig.json 文件:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],
    "paths": {
      "@auth/*": [
        "src/app/auth/*"
      ],
      "@core/*": [
        "src/app/core/*"
      ],
      "@entities/*": [
        "src/app/entities/*"
      ],
      "@shared/*": [
        "src/app/shared/*"
      ],
      "@env/*": [
        "src/environments/*"
      ],
      "@reducers/*": [
        "src/app/reducers/*"
      ],
    }
  }
}

我遇到了同样的问题。我的 tsconfig.server.json 有参数 "baseUrl": "."。它覆盖 tsconfig.json 参数 "baseUrl": "./"。我刚刚删除了它,现在可以在我这里使用了

tsconfig.server.json 之前

{
  "extends": "./tsconfig.app.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app-server",
    "baseUrl": "."
  },
  "angularCompilerOptions": {
    "entryModule": "app/app.server.module#AppServerModule"
  }
}

tsconfig.服务器.json 之后

{
  "extends": "./tsconfig.app.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app-server",
  },
  "angularCompilerOptions": {
    "entryModule": "app/app.server.module#AppServerModule"
  }
}