Angular 7 Universal-无法解析路径

时间:2018-12-09 08:18:32

标签: angular url-routing angular7 serverside-rendering angular-universal

我遵循了有关使用Angular Universal进行服务器端渲染的出色教程 https://angularfirebase.com/lessons/server-side-rendering-firebase-angular-universal/

但是在运行npm run build:ssr && npm run serve:ssr时,出现以下错误:

errors

以某种方式,它无法识别我在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/*"
      ],
    }
  }
}

1 个答案:

答案 0 :(得分:0)

我有同样的问题。我的tsconfig。服务器 .json具有参数“ baseUrl”:“。”。它会覆盖tsconfig.json参数“ baseUrl”:“ ./”。我刚刚删除了它,现在可以从我这里使用

tsconfig。服务器 .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"
  }
}