简体   繁体   English

无法解析tsconfig路径

[英]Cannot resolve tsconfig paths

My Angular 6 project with TypeScript version "2.7.2" has tsconfig.json as 我的带有TypeScript版本“2.7.2”的Angular 6项目的tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./src",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  },
  "paths":{
    "@services/*": ["app/services/*"] 
  }
 }

I tried importing a service using the above path 我尝试使用上述路径导入服务

 import { AppService } from '@services/app.service';

But I'm getting this error on running ng serve 但是我在运行ng serve遇到了这个错误

ERROR in src/app/app.module.ts(20,26): error TS2307: Cannot find module '@services/app.service'. src / app / app.module.ts(20,26)中的错误:错误TS2307:找不到模块'@ services / app.service'。

PS- Without the paths PS-没有路径

import { AppService } from './services/app.service';

is working fine. 工作正常。

paths option is part of compilerOptions paths选项是compilerOptions一部分

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./src",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "paths":{
      "@services/*": ["app/services/*"] 
    }
  },
 }

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

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