[英]Appears in the NgModule.imports of ExtendedSearchModule, but itself has errors?
[英]error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors
我在本地和建筑项目中有 angular 12,它运行良好,没有任何错误。
我的本地设置:
Angular CLI: 12.0.5
Node: 12.16.3
Package Manager: npm 6.14.4
OS: win32 x64
Angular: 12.0.5
但是在 linux 服务器上构建我的项目时,它给出了这个错误,没有什么可以解决的。
服务器设置:
Angular CLI: 12.0.5
Node: 14.18.1
Package Manager: npm 6.14.15
OS: linux x64
Angular: 12.0.5
Error: src/app/app-routing.module.ts:34:14 - error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors
34 export class AppRoutingModule { }
应用程序模块.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { HeaderComponent } from './header/header.component';
import { FooterComponent } from './footer/footer.component';
import { NotifyFormComponent } from './notify-form/notify-form.component';
import { LoginComponent } from './login/login.component';
@NgModule({
declarations: [
AppComponent,
HomeComponent,
HeaderComponent,
FooterComponent,
NotifyFormComponent,
LoginComponent
],
imports: [
AppRoutingModule,
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
应用程序路由.module.ts
import { LoginComponent } from './login/login.component';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { NotifyFormComponent } from './notify-form/notify-form.component';
import { HomeComponent } from './home/home.component';
const routes: Routes = [
{path:'',redirectTo:'/',pathMatch: 'full'},
{
path:'',
component: HomeComponent,
children:[
]
},
{
path:'notify',
component: NotifyFormComponent
},
{
path:'login',
component: LoginComponent
}
// {
// path:'**',
// component: HomeComponent
// }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2017",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
如果我在这里做错了什么,请帮助我。 这只是一个简单的测试项目。 非常感谢。
我进行了一些研究,这是一个官方问题https://github.com/angular/angular/issues/35399 。 这里还有另一个问题, 错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule 类。 但我会继续总结我发现的东西。
对于许多人来说,它只是简单地重新启动和重建项目,或者完全强制清除 npm 缓存并重新安装 node_modules 并重建它。
人们建议在 tsconfig 工作中禁用“ivy”,但是也有人提到,虽然它有效,但它不是推荐的修复方法。
如果您将组件添加到导入而不是声明,这显然也会发生。
如果您以 root 身份安装了一些软件包,或者由于某种原因您没有对所有软件包的权限,这显然也会发生。 这是通过在目录上执行 chown 来修复的,但是真正的解决方案是首先正确安装软件包并配置 npm 配置,因此您永远不会安装具有 root 权限的软件包。 因此,本质上,如果您使用 root 安装软件包并尝试以非 root 身份运行该项目,则会出现此问题。
有些人在向导入而不是提供者添加服务时遇到错误。
如果人们错误地命名包,即 SomeComponent 而不是 SomeComponentModule,也会出现此错误。
在您的特定情况下,您在浏览器模块之前导入了应用程序路由器,我不知道这是否会导致问题,但我所看到的所有地方都在应用程序之前添加了浏览器模块,因此如果没有其他工作,请交换它们,看看是否有效。
这就是我能找到的一切。
您必须检查是否将所需的所有内容导入 app.module.ts,然后检查 linux 也许您需要添加任何其他组件,但这样应该可以正常工作
尝试 npm 版本应该 > 8.1.0 并且节点版本应该 > v16.13.0
当我将项目从 Windows 转移到 Linux 时,我遇到了这个问题。
我的模块的导入路径有大写字母,这在 linux 中失败并在 Windows 中工作。
例如,以下任一项都可以在 Windows 上运行:
import { switchMap, tap } from 'rxjs/operators';
import { switchMap, tap } from 'rxjs/Operators';
在 Linux 上,只有小写版本可以工作:
import { switchMap, tap } from 'rxjs/operators';
我用ng serve命令解决了这个问题。当您更改 angular.json 文件中的配置时,您会遇到这个问题。
检查'templateUrl'和'styleUrls'中提到的路径在与有问题的模块相关的组件中是否正确,
@Component({
selector: 'app-navigation-menu-item',
templateUrl: './xxx.component.html',
styleUrls: ['./xxx.component.scss']
})
就我而言,这是错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.