2

我有一个较旧的 Angular 项目,其中已经制作了一些组件。角度语言服务不适用于使用 cli 生成的新组件,

今天生成的新组件: HTML 那么这里是 ts 文件: ts文件

但是,如果您查看几天前生成的同一项目中的另一个组件,它可以工作:

[工作][1]

ts文件: ts文件

我认为这是一个 IVY 问题,所以我继续在 angular.json 中禁用 AOT,并在我的 ts 配置中添加了 "enableIvy": false,以下是这些文件:

Angular.json

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "frontend": {
            "projectType": "application",
            "schematics": {
                "@schematics/angular:component": {
                    "style": "scss"
                }
            },
            "root": "",
            "sourceRoot": "src",
            "prefix": "app",
            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": {
                        "outputPath": "dist/frontend",
                        "index": "src/index.html",
                        "main": "src/main.ts",
                        "polyfills": "src/polyfills.ts",
                        "tsConfig": "tsconfig.app.json",
                        "aot": false,
                        "assets": ["src/favicon.ico", "src/assets"],
                        "styles": [
                            "src/styles.scss",
                            "node_modules/material-design-icons/iconfont/material-icons.css"
                        ],
                        "scripts": []
                    },
                    "configurations": {
                        "production": {
                            "fileReplacements": [
                                {
                                    "replace": "src/environments/environment.ts",
                                    "with": "src/environments/environment.prod.ts"
                                }
                            ],
                            "optimization": true,
                            "outputHashing": "all",
                            "sourceMap": false,
                            "extractCss": true,
                            "namedChunks": false,
                            "extractLicenses": true,
                            "vendorChunk": false,
                            "buildOptimizer": true,
                            "budgets": [
                                {
                                    "type": "initial",
                                    "maximumWarning": "2mb",
                                    "maximumError": "5mb"
                                },
                                {
                                    "type": "anyComponentStyle",
                                    "maximumWarning": "6kb",
                                    "maximumError": "10kb"
                                }
                            ]
                        }
                    }
                },
                "serve": {
                    "builder": "@angular-devkit/build-angular:dev-server",
                    "options": {
                        "browserTarget": "frontend:build"
                    },
                    "configurations": {
                        "production": {
                            "browserTarget": "frontend:build:production"
                        }
                    }
                },
                "extract-i18n": {
                    "builder": "@angular-devkit/build-angular:extract-i18n",
                    "options": {
                        "browserTarget": "frontend:build"
                    }
                },
                "test": {
                    "builder": "@angular-devkit/build-angular:karma",
                    "options": {
                        "main": "src/test.ts",
                        "polyfills": "src/polyfills.ts",
                        "tsConfig": "tsconfig.spec.json",
                        "karmaConfig": "karma.conf.js",
                        "assets": [
                            "src/favicon.ico",
                            "src/assets",
                            {
                                "glob": "**/*",
                                "input": "node_modules/ngx-auth-firebaseui/assets/",
                                "output": "./assets/"
                            }
                        ],
                        "styles": [
                            "src/styles.scss",
                            "node_modules/material-design-icons/iconfont/material-icons.css"
                        ],
                        "scripts": []
                    }
                },
                "lint": {
                    "builder": "@angular-devkit/build-angular:tslint",
                    "options": {
                        "tsConfig": [
                            "tsconfig.app.json",
                            "tsconfig.spec.json",
                            "e2e/tsconfig.json"
                        ],
                        "exclude": ["**/node_modules/**"]
                    }
                },
                "e2e": {
                    "builder": "@angular-devkit/build-angular:protractor",
                    "options": {
                        "protractorConfig": "e2e/protractor.conf.js",
                        "devServerTarget": "frontend:serve"
                    },
                    "configurations": {
                        "production": {
                            "devServerTarget": "frontend:serve:production"
                        }
                    }
                }
            }
        }
    },
    "defaultProject": "frontend"
}

tsconfig.app.json

{
    "extends": "./tsconfig.base.json",
    "compilerOptions": {
        "outDir": "./out-tsc/app",
        "types": []
    },
    "files": ["src/main.ts", "src/polyfills.ts"],
    "include": ["src/**/*.d.ts"],
    "angularCompilerOptions": {
        "enableIvy": false
    }
}

tsconfig.json:

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
]
}

tsconfig.base.json

{
    "compileOnSave": false,
    "compilerOptions": {
        "baseUrl": "./",
        "outDir": "./dist/out-tsc",

        "sourceMap": true,
        "declaration": false,
        "downlevelIteration": true,
        "experimentalDecorators": true,
        "moduleResolution": "node",
        "importHelpers": true,
        "target": "es2015",
        "module": "es2020",
        "lib": ["es2018", "dom"]
    }
}

编辑
我从头开始生成了一个全新的项目,问题似乎仅限于这个项目。它适用于新项目中的新组件。只是在旧版本中不起作用。

当我为项目提供服务时,我收到了这些我从未见过或理解的警告,但项目仍然可以编译:

WARNING in /Users/raphaelcastro/Documents/Programing/Development/partnerDataEntryProject/frontend/node_modules/@angular/fire/fesm2015/angular-fire-firestore.js depends on '@firebase/app'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /Users/raphaelcastro/Documents/Programing/Development/partnerDataEntryProject/frontend/node_modules/@angular/fire/fesm2015/angular-fire.js depends on 'firebase/app'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /Users/raphaelcastro/Documents/Programing/Development/partnerDataEntryProject/frontend/node_modules/ngx-auth-firebaseui/fesm2015/ngx-auth-firebaseui.js depends on '@firebase/auth'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /Users/raphaelcastro/Documents/Programing/Development/partnerDataEntryProject/frontend/node_modules/@angular/fire/fesm2015/angular-fire-firestore.js depends on '@firebase/firestore'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
4

2 回答 2

7

我有同样的问题,它发生在 vscode 询问我是否要启用 Experimental-ivy 并且我点击是之后!在我的头撞到墙上 24 小时后,我不得不再次禁用它。

方法如下: 如何禁用 Experimental-ivy

于 2021-02-14T11:15:50.450 回答
0

实验性常春藤的设置现在从 Angular 语言服务中消失了

于 2021-09-16T15:43:14.947 回答