【问题标题】:Angular 7 File '../src/types/@angular/common.d.ts' is not a moduleAngular 7 文件 '../src/types/@angular/common.d.ts' 不是模块
【发布时间】:2019-05-27 12:39:31
【问题描述】:

我创建了一个新的 Angular 7 项目,并且在 ap.routing.ts 我有

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Routes } from '@angular/router';
import { ClientsComponent } from './components/clients/clients.component';
import { HomeComponent } from './components/commons/home/home.component';
import { FunctionalitiesComponent } from './components/functionalities/functionalities.component';
import { ProcessesComponent } from './components/processes/processes.component';
import { ProjectsComponent } from './components/projects/projects.component';
import { UsersComponent } from './components/users/users.component';
import { AuthenticationGuard } from './_guards/authentication.guard';
import { LoginComponent } from './components/users/login/login.component';
import { RegistrationComponent } from './components/users/registration/registration.component';



const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: 'home', component: HomeComponent, canActivate: [AuthenticationGuard] },
  { path: 'clients', component: ClientsComponent },
  { path: 'projects', component: ProjectsComponent },
  { path: 'functionalities', component: FunctionalitiesComponent },
  { path: 'processes', component: ProcessesComponent },
  { path: 'login', component: LoginComponent },
  { path: 'users', component: UsersComponent }

];

@NgModule({
  imports: [
    CommonModule,
    BrowserModule,
    RouterModule.forRoot(routes, { enableTracing: true , onSameUrlNavigation: 'reload'})
  ],
  exports: [
  ],
})
export class AppRoutingModule { }

'@angular/common'红色下划线,报错如下:

File '{pathTo}/src/types/@angular/common.d.ts' is not a module

我已经安装了模块使用

npm i @angular/common

重新启动可视化编辑器(VS Code),重新运行ng serve,但没有任何改变。
这是 package.json 文件:

{
  "name": "material-dashboard-angular",
  "version": "2.2.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --base-href /admin/",
    "build": "ng build --aot --base-href /admin/",
    "build-prod": "ng build --prod --aot",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && ng serve -o"
  },
  "engines": {
    "node": "6.11.1",
    "npm": "3.10.9"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "1.0.0-beta.5",
    "@angular/animations": "7.0.2",
    "@angular/cdk": "7.0.2",
    "@angular/common": "7.0.2",
    "@angular/compiler": "7.0.2",
    "@angular/core": "7.0.2",
    "@angular/forms": "7.0.2",
    "@angular/http": "7.0.2",
    "@angular/material": "7.0.2",
    "@angular/platform-browser": "7.0.2",
    "@angular/platform-browser-dynamic": "7.0.2",
    "@angular/platform-server": "7.0.2",
    "@angular/router": "7.0.2",
    "@auth0/angular-jwt": "^2.1.0",
    "@ngx-translate/core": "^11.0.1",
    "@ngx-translate/http-loader": "^4.0.0",
    "acorn": "^6.1.1",
    "ajv": "6.4.0",
    "angular-http-server": "^1.9.0",
    "angular-svg-icon": "^7.2.1",
    "arrive": "2.4.1",
    "bootstrap": "4.1.0",
    "bootstrap-material-design": "4.1.1",
    "bootstrap-notify": "3.1.3",
    "chartist": "0.11.0",
    "classlist.js": "1.1.20150312",
    "core-js": "2.4.1",
    "cron-validator": "^1.0.1",
    "express": "4.16.3",
    "file-input-accessor": "^7.0.0",
    "googleapis": "28.1.0",
    "hammerjs": "2.0.8",
    "jquery": "^3.4.1",
    "moment": "2.22.1",
    "perfect-scrollbar": "1.1.0",
    "popper.js": "1.14.3",
    "rxjs": "6.3.3",
    "rxjs-compat": "6.3.3",
    "sancronos-validator": "^1.2.0",
    "web-animations-js": "2.3.1",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.13.9",
    "@angular/cli": "6.0.3",
    "@angular/compiler-cli": "^7.2.15",
    "@angular/language-service": "7.0.2",
    "@types/bootstrap": "3.3.32",
    "@types/chartist": "0.9.34",
    "@types/googlemaps": "3.30.8",
    "@types/jasmine": "2.5.38",
    "@types/jquery": "1.10.31",
    "@types/node": "^6.0.73",
    "codelyzer": "4.2.1",
    "jasmine-core": "3.1.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "^4.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "1.4.2",
    "karma-jasmine": "1.1.1",
    "protractor": "^6.0.0",
    "ts-node": "5.0.1",
    "tslint": "5.9.1",
    "typescript": "3.1.6"
  }
}

错误日志

错误 node_modules/@angular/cdk/overlay/typings/overlay-ref.d.ts(11,26): 错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。 node_modules/@angular/cdk/overlay/typings/overlay.d.ts(9,26):错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。 node_modules/@angular/material/bottom-sheet/typings/bottom-sheet-ref.d.ts(8,26): 错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。 node_modules/@angular/material/bottom-sheet/typings/bottom-sheet.d.ts(11,26): 错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。 node_modules/@angular/material/dialog/typings/dialog-ref.d.ts(9,26): 错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。 node_modules/@angular/material/dialog/typings/dialog.d.ts(10,26): 错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。 node_modules/@angular/platform-b​​rowser/src/browser/location/browser_platform_location.d.ts(8,58): 错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。 node_modules/@angular/router/src/directives/router_link.d.ts(8,34): 错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。 node_modules/@angular/router/src/router.d.ts(8,26): 错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。 node_modules/@angular/router/src/router_module.d.ts(8,106):错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。 node_modules/@angular/router/src/router_scroller.d.ts(8,34):错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。 src/app/app.routing.ts(1,30):错误 TS2306:文件 'C:/Users/Marina/Desktop/heliosFrontEnd_admin/src/types/@angular/common.d.ts' 不是一个模块。

【问题讨论】:

  • 将您的 @angular/common 降级到 7.0.2,或升级其他所有内容。
  • 什么都没有改变,还是同样的错误:\
  • 另外,在可以找到package.json的目录中运行npm install
  • 嗨,我做到了,但没有任何改变。我已经用错误日志更新了问题

标签: angular angular7


【解决方案1】:

根据您的错误日志,您正在使用 MatBottomSheet。所以你需要从@angular/material 导入 MatBottomSheetModule。也将它包含在导入数组中。

在角材料中,每个组件都有自己的模块。因此,在使用该组件之前,请导入它的相关模块。

【讨论】:

  • 您是否在项目中的任何地方使用角度/材质?任何类似
  • 是的,在某些组件中我使用import { MatDialog } from '@angular/material';
  • 然后在app模块中添加以下内容。从“@angular/material”导入 {MatDialogModule}。还要在导入数组中添加 MatDialogModule。
  • AppModule中是否导入了材质组件相关模块?
猜你喜欢
  • 1970-01-01
  • 2019-12-10
  • 2019-04-18
  • 2019-11-28
  • 2020-11-21
  • 2020-01-28
  • 2018-06-30
  • 2019-07-02
  • 2019-07-12
相关资源
最近更新 更多