我的本地和建筑專案中的 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 { }
app.module.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 { }
app-routing.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 { }
組態檔
{
"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
}
}
如果我在這里做錯了什么,請幫助我。這只是一個簡單的測驗專案。非常感謝。
uj5u.com熱心網友回復:
我進行了一些研究,這是一個官方問題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,也會出現此錯誤。
在您的特定情況下,您在瀏覽器模塊之前匯入了應用程式路由器,我不知道這是否會導致問題,但我所看到的所有地方都在應用程式之前添加了瀏覽器模塊,因此如果沒有其他作業,請交換它們看看是否有效。
這就是我能找到的一切。
uj5u.com熱心網友回復:
您必須檢查是否將所需的所有內容匯入 app.module.ts 然后檢查 linux 也許您需要添加任何其他組件,但它應該可以正常作業
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/343881.html
標籤:javascript 节点.js 有角的 打字稿 角12
