Visual Studio代码-导入路径已损坏

时间:2018-08-06 01:05:55

标签: typescript visual-studio-code

我开始输入@Component(),而VS Code无法正确解析导入路径。

预期结果:

import { Component } from "@angular/core";

观察结果:

import { Component } from "../../../../node_modules/@angular/core";

有人有什么错的想法吗?


更新1

tsconfig.json

{
    "compilerOptions": {
        "declaration": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "lib": [
            "es6",
            "dom"
        ],
        "mapRoot": "./",
        "module": "es6",
        "moduleResolution": "node",
        "outDir": "../dist/out-tsc",
        "sourceMap": true,
        "target": "es5",
        "typeRoots": [
            "../node_modules/@types"
        ],
        "baseUrl": ".",
        "paths": {
            "@shared/*": [
                "./shared/*"
            ],
            "@app/*": [
                "./app/*"
            ],
            "@global/*": [
                "./global/*"
            ]
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您可以使用此命令更好地了解问题所在

  

tsc --traceResolution | grep @shared

最有可能您的baseUrl和路径不正确匹配