Angular 7:npm安装后找不到node_modules

时间:2019-11-29 14:11:17

标签: angular npm node-modules

直到今天下午,我的angular 7项目都运行良好。当我做完ng服务时,出现以下错误:node_modules/@angular/common/http/src/client.d.ts(2514,30): error TS2304: Cannot find name 'ArrayBuffer'. node_modules/@angular/common/http/src/client.d.ts(2580,30): error TS2304: Cannot find name 'Object'. node_modules/@angular/common/http/src/client.d.ts(2621,33): error TS2304: Cannot find name 'ArrayBuffer'. 一直到所有node_modules结束。我尝试删除node_module文件夹,然后“ npm install”。仍然没有用。

这是我的package.json文件

{
  "name": "cotrajectplanner2",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "angular-chart.js": "^1.1.1",
    "bootstrap": "^4.4.1",
    "chart.js": "^2.9.3",
    "core-js": "^2.5.4",
    "jquery": "^3.4.1",
    "jqwidgets-ng": "^8.3.2",
    "popper.js": "^1.16.0",
    "router": "^1.3.3",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.3",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "3.1.1"
  }
}

预先感谢

真诚的萨拉

编辑:添加了app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { LoginComponent } from './general/login/login.component';
import { RouterModule } from '@angular/router';
import { AppRoutingModule } from './app-routing.module';
import { HomeStudentComponent } from './student/home-student/home-student.component';
import { HomeTeacherComponent } from './teacher/home-teacher/home-

teacher.component';
import { StudentInfoComponent } from './student/student-info/student-info.component';
import { StudentStudyProgressComponent } from './student/student-study-progress/student-study-progress.component';
import { StudentOnMyWayToComponent } from './student/student-on-my-way-to/student-on-my-way-to.component';
import { OverviewTrajectoriesComponent } from './teacher/overview-trajectories/overview-trajectories.component';
import { OverviewCoursesComponent } from './teacher/overview-courses/overview-courses.component';
import { OverviewStudentsComponent } from './teacher/overview-students/overview-students.component';
import {HttpClientModule} from '@angular/common/http';
import { FooterComponent } from './general/footer/footer.component';
import { HeaderComponent } from './general/header/header.component';

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    HomeStudentComponent,
    HomeTeacherComponent,
    StudentInfoComponent,
    StudentStudyProgressComponent,
    StudentOnMyWayToComponent,
    OverviewTrajectoriesComponent,
    OverviewCoursesComponent,
    OverviewStudentsComponent,
    FooterComponent,
    HeaderComponent
  ],
  imports: [
    BrowserModule,
    RouterModule,
    AppRoutingModule,
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

2 个答案:

答案 0 :(得分:0)

执行此cmd-npm init

有关更多详细信息,请单击此链接-npm install doesn't create node_modules directory

答案 1 :(得分:0)

我建议您进行以下操作

  1. 删除文件系统上的node_modules
  2. 在文件系统上创建目录node_modules
  3. npm cache clean
  4. npm i

建议的解决方案:

import {HttpClient} from '@angular/common/http'

删除

import {HttpClientModule} from '@angular/common/http';