我在VSCode中使用angular时遇到了一个问题。问题是它说没有ngModules,(不知何故,这是因为AngularIvy),比如:
[{
"resource": "[...]src/app/components/basic-info-card/basic-info-card.module.ts",
"owner": "_generated_diagnostic_collection_name_#4",
"code": "-996002",
"severity": 8,
"message": "'CommonModule' does not appear to be an NgModule class.",
"startLineNumber": 13,
"startColumn": 5,
"endLineNumber": 13,
"endColumn": 17,
"relatedInformation": [
{
"startLineNumber": 22,
"startColumn": 39,
"endLineNumber": 22,
"endColumn": 39,
"message": "This likely means that the library (@angular/common) which declares CommonModule is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.",
"resource": "not+gona+show"
}
]
}]
字符串
但“CommonModule”不仅是类(和项目)的一部分......而且它也不应该与Angular Ivy有问题,考虑到我在tsconfidg.app.json中使用以下命令停用了它:
...
"angularCompilerOptions": {
"enableIvy": false
}
型
我们应该在一个名为“project”的角项目中创建一个名为“my-project”的模块(显然我改名了)。
请帮帮我
有所帮助的信息
系统:Windows 10家庭Avast免费
VSCODE版本
Version: 1.80.1 (user setup)
Commit: 74f6148eb9ea00507ec113ec51c489d6ffb4b771
Date: 2023-07-12T17:22:07.651Z
Electron: 22.3.14
ElectronBuildId: 21893604
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.22621
型
ANGULAR版本
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 8.3.17
Node: 14.21.3
OS: win32 x64
Angular: 8.2.13
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.803.29
@angular-devkit/build-angular 0.803.29
@angular-devkit/build-ng-packagr 0.803.29
@angular-devkit/build-optimizer 0.803.29
@angular-devkit/build-webpack 0.803.29
@angular-devkit/core 8.3.29
@angular-devkit/schematics 8.3.17
@angular/cdk 8.2.3
@angular/cli 8.3.17
@angular/material 8.2.3
@ngtools/webpack 8.3.29
@schematics/angular 8.3.17
@schematics/update 0.803.17
ng-packagr 5.7.1
rxjs 6.5.3
typescript 3.5.3
webpack 4.39.2
型
package.json:
{
"name": "project",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"icons": "fantasticon"
},
"private": true,
"dependencies": {
"@angular/animations": "8.2.13",
"@angular/cdk": "8.2.3",
"@angular/common": "8.2.13",
"@angular/compiler": "8.2.13",
"@angular/core": "8.2.13",
"@angular/forms": "8.2.13",
"@angular/material": "8.2.3",
"@angular/platform-browser": "8.2.13",
"@angular/platform-browser-dynamic": "8.2.13",
"@angular/router": "8.2.13",
"@ngrx/effects": "8.4.0",
"@ngrx/store": "8.4.0",
"fantasticon": "1.2.3",
"install": "^0.13.0",
"material-design-icons": "3.0.1",
"ng-packagr": "5.7.1",
"rxjs": "6.5.3",
"tslib": "^1.10.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.17",
"@angular-devkit/build-ng-packagr": "~0.803.17",
"@angular/cli": "8.3.17",
"@angular/compiler-cli": "8.2.13",
"@angular/language-service": "8.2.13",
"@types/node": "12.12.6",
"@types/jasmine": "~4.0.0",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "10.9.1",
"tsickle": "^0.37.0",
"tslint": "~5.15.0",
"typescript": "3.5.3"
},
"angularCompilerOptions": {
"strictTemplates": true,
"enableIvy": false
}
}
型
angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"project": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/project",
"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"
],
"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,
"aot": true,
"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": "project:build"
},
"configurations": {
"production": {
"browserTarget": "project:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "project: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"
],
"styles": [
"src/styles.scss"
],
"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": "project:serve"
},
"configurations": {
"production": {
"devServerTarget": "project:serve:production"
}
}
}
}
},
"my-project": {
"projectType": "library",
"root": "projects/my-project",
"sourceRoot": "projects/my-project/src",
"prefix": "edge",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/my-project/tsconfig.lib.json",
"project": "projects/my-project/ng-package.json"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/my-project/src/test.ts",
"tsConfig": "projects/my-project/tsconfig.spec.json",
"karmaConfig": "projects/my-project/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/my-project/tsconfig.lib.json",
"projects/my-project/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}},
"defaultProject": "project"
}
型
我的tsconfig.json:
{
"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": {
"my-project": [
"dist/my-project"
],
"my-project/*": [
"dist/my-project/*"
]
}
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictTemplates": true,
"strictInjectionParameters": true
}
}
型
我尽力了,
- 重启Angular 服务器,
- 删除
node_module
和npm install
, - 删除
node_module
和npm i --unsafe-perm --verbose install
, - 删除
node_module
、npm cache clean --force
和npm install
, - 删除
node_module
、npm cache clean --force
和npm i --unsafe-perm --verbose install
,
我真的不知道我还能做些什么来让它工作。其他人在Linux中使用它就好了,但我使用的是Windows,我怀疑这是唯一的问题。
我甚至多次尝试重新安装Angular,但从未成功过。我的选项已经用完了,这些错误阻碍了我按照我想要的方式进行测试。
我现在怀疑这是与vscode有关的东西,因为我尝试了基本上所有其他的手段,我知道关闭
1条答案
按热度按时间w6mmgewl1#
安装早期版本的Angular语言服务扩展,对于Angular 8项目,版本v11.1.3似乎工作正常-