日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

关于 Angular 项目类型为 library 的工程使用 tsconfig.json 的问题

發布時間:2023/12/19 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于 Angular 项目类型为 library 的工程使用 tsconfig.json 的问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我今天做 Angular 開發時,遇到一個很奇怪的問題:

在某個 Angular library 項目里,無法正確解析出 @Spartacus/core,

錯誤消息:

Cannot find module ‘@spartacus/core’ or its corresponding type declarations.ts(2307)

但是,就在同一工程的單元測試 .spec.ts 文件里,庫的解析是正確的。這種在同一文件夾里不同文件對另外同一個庫的解析,出現如此不一致的現象,讓我非常費解。

后來經過一番分析,發現是庫文件夾里文件 tsconfig.json 引起的原因。

我把該文件的內容清空只剩下面一行,問題消失。

最后問題定位到,加了下圖這三行進行 paths 設置后,就出問題了:

"paths": {"@spartacus/core": ["dist/core"],"@spartacus/storefront": ["dist/storefrontlib"],"@spartacus/cart": ["dist/cart"]},

每次 Visual Studio Code 里修改了 tsconfig.json 之后,都會顯示 Initializing Angular Language features:

目錄中存在 tsconfig.json 文件表明該目錄是 TypeScript 項目的根目錄。 tsconfig.json 文件指定了編譯項目所需的根文件和編譯器選項。

https://stackoverflow.com/questions/52147201/angular-6-declare-path-for-library-in-tsconfig-lib-json

Angular will use the tsconfig.json file, which is configured in the angular.json file in architect --> build --> options --> tsconfig. Whereas VS Code uses the tsconfig.json file, which is at the bottom of the workspace. You need to add the paths in both configurations to get both of them to work correctly, or change the project to use the base tsconfig.json file in the angular.json file.

The tsconfig.json file has a property that extends which will take another file as base and override everything which are declared in the tsconfig.lib.json file. So if you have paths declared in the tsconfig.lib.json file, then the paths are no longer needed in the tsconfig.json file.

更多Jerry的原創文章,盡在:“汪子熙”:

總結

以上是生活随笔為你收集整理的关于 Angular 项目类型为 library 的工程使用 tsconfig.json 的问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。