更新到 Angular 18 并选择 Vite 作为构建工具后,某些包未解析,即:
X [ERROR] Could not resolve "@angular/common/http"
../../../../http-options.ts:1:27:
1 │ import { HttpParams } from "@angular/common/http";
╵ ~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "@angular/common/http" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
问题是,我有两个项目和两个 package.json 文件,其中一个在 tsconfig.json 文件的帮助下引用其他包:
"paths": {
"@angular/*": [ "../node_modules/@angular/*" ],
我安装了“vite-tsconfig-paths”并添加了 vite.config.ts 文件。但这并没有解决问题。我还在 vite 配置中添加了解析别名。
最重要的是我想知道这是否可能。或者如果有其他方法来设置它就更好了。
创建一个新分支来保留您的更改,然后删除两个项目中的这些
"paths"
并尝试 npm link
方法,我假设您有一个项目和一个使用该项目的应用程序。
确保在 angular.json 中为所有使用链接的项目设置了
"preserveSymlinks": true
。
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
...
"preserveSymlinks": true,
本教程非常适合使用链接包。