简体   繁体   English

ng 测试运行因 tsconfig 路径映射而失败

[英]ng test run fail with tsconfig path mapping

I've configured tsconfig.json for path mapping to import like this:我已将tsconfig.json配置为导入路径映射,如下所示:

{
    "compilerOptions": {
       "paths" : {
         "@enum/*": [
           "src/app/enum/*"
         ],
         "@util/*": [
           "src/app/util/*"
         ]
       }
    }
}

I've a class OrderService:我有一个 class OrderService:

import {DateUtil} from "@util/date_util";
@Injectable({providedIn: 'root'})
export class OrderService {

  //Some codes implement here

}

I write test case for class OrderService and run ng test , this issue occurs:我为 class OrderService编写测试用例并运行ng test ,出现此问题:

error TS2307: Cannot find module '@util/date_util'.错误 TS2307:找不到模块“@util/date_util”。

Anyone can help me to resolve the problem?任何人都可以帮我解决问题吗?

You forgot the paths property inside compiler options您忘记了编译器选项中的路径属性

{
  "compilerOptions": {
    "paths": {
      "@enum/*": [
        "src/app/enum/*"
      ],
      "@util/*": [
        "src/app/util/*"
      ]
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM