【问题标题】:Karma Runner doesnt find path to ES6 module from tsconfig.jsonKarma Runner 找不到从 tsconfig.json 到 ES6 模块的路径
【发布时间】:2018-05-18 10:20:20
【问题描述】:

我正在尝试加载生成 Karma Config 的外部模块。这个模块基本上提供了 karma.config.js 的内容

这是一个 Angular 6 项目。设置是这样的,我的 tsconfig.json 看起来像

{
  "compileOnSave": true,
  "compilerOptions": {
    "module": "commonjs",
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedParameters": true,
    "skipLibCheck": true,
    "strictNullChecks": true,
    "sourceMap": true,
    "newLine": "LF",
    "moduleResolution": "node",
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "paths": {
      "test-config": [
        "dist/test-config"
      ]
    }
  }
}

test-config 指向 dist/test-config 的映射。我验证了这个目录存在并且它的内容是真实的。

对于 angular.json,我会说类似

 "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "projects/components/src/test.ts",
            "tsConfig": "projects/components/tsconfig.json",
            "karmaConfig": "projects/components/karma.config.ts"
          }
        },

我的 karma.config.ts 将外部 es6 模块加载为其第一行。

import { ExtendedKarmaConfig } from "test-config";

当我通过命令 ng test 触发 karma runner 时,尝试查找 test-config 失败。我该如何解决这个问题?

【问题讨论】:

    标签: angular karma-runner es6-modules


    【解决方案1】:

    您应该将文件移动到其他位置。 '/dist' 在 cli 构建时被删除。另外,您告诉 TS 在目录 /dist/test-config 下找到 test-config。

    【讨论】:

    • dist 文件夹实际上是由 ng build 生成的。当您指定 test-config 项目的绝对路径时,该问题已得到解决。
    猜你喜欢
    • 1970-01-01
    • 2020-10-24
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    • 2022-08-11
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    相关资源
    最近更新 更多