簡體   English   中英

Angular8 無法識別添加到 tsConfig 文件的自定義路徑

[英]custom paths added to tsConfig file aren't recognized in Angular8

我在我的 tsConfig 文件中添加了一個自定義路徑,並找出 Angular 無法識別它的原因。 我注意到 angular 已經有一個baseUrl屬性設置為./我假設它從 tsConfig 文件所在的當前文件夾開始。我添加的代碼看起來像這樣

"paths": {
      "@interfaces/*": ["src/app/interfaces/*"]
    }

當我嘗試將其導入組件時,這會引發 TS2307錯誤。 我的整個 ts.config 文件看起來像這樣

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],
    "paths": {
      "@interfaces/*": ["src/app/interfaces/*"]
    }
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

我需要做什么才能讓它發揮作用?

我剛剛啟動了 VSCode,突然間錯誤消失了。 我打開了節點終端,運行我的ng serve並使用 VSCode 中的終端生成組件。 也許那里的某些東西以某種方式自我更新。 在我關閉並重新提供我的項目之前,它可以使用更新重新編譯,但僅此一項似乎不起作用。 希望這可以將具有更多“幕后”經驗的人指向一個錯誤,如果這基本上不應該是一個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM