Angular 7 Universal - 无法解析路径

标签 angular url-routing angular7 server-side-rendering angular-universal

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

但是当运行npm run build:ssr && npm runserve: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/*"
      ],
    }
  }
}

最佳答案

我也遇到了同样的问题。我的 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.server.json 之后

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

关于Angular 7 Universal - 无法解析路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53690541/

相关文章:

angular - 多个 canActivate 守卫在第一次失败时全部运行

mysql - Sequelize - 插入长记录的最佳方式

第一页加载时的javascript window.history API

asp.net-mvc-3 - 添加asp.net mvc 3的路由

angular7 - 未找到 Angular 7 prod build i18n 文件

javascript - 在 JAVASCRIPT 中创建 UTC 日期对象

angular - Ionic - 滚动到页面的元素

php - TYPO3.CMS 9 LTS - 可缓存 extbase 操作,但新路由没有 cHash

rxjs - BehaviorSubject 发射两次

javascript - Angular 7 找不到类型为 '[object Object]' 的不同支持对象 'object'。 NgFor 仅支持绑定(bind)到 Iterables,例如 Arrays