【问题标题】:Angular 7: node_modules not found after npm installAngular 7:npm install 后找不到 node_modules
【发布时间】:2020-03-25 03:28:10
【问题描述】:

直到今天下午,我的 angular 7 项目一直运行良好。当我执行“ng serve”时,我得到了这些错误: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 { }

【问题讨论】:

  • 介意向我们展示您的 module.ts 文件,您在其中导入了 @angular/common/http-client?
  • 请注意,据我所知,您目前正在使用 Angular 7
  • 感谢您的 cmets。我采纳了你的建议:)

标签: angular npm node-modules


【解决方案1】:

我建议做以下事情

  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';

【讨论】:

  • 感谢您的回答。不幸的是,这对我没有帮助。我仍然遇到同样的错误
  • 如果我只是在开始阶段创建一个新项目是否有用?我只是不希望它再次发生
  • 嘿@SarahDeCock,你能尝试导入以下内容吗:import {HttpClient} from '@angular/common/http';
  • 真的谢谢你!添加您在 app.module.ts 中建议的内容后,它起作用了!我仍然不明白为什么一行代码会导致这样的错误,并且在 module.ts 中没有使用该导入。不过非常感谢!
【解决方案2】:

执行这个 cmd - npm init

更多详情请点击此链接-npm install doesn't create node_modules directory

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-26
  • 2020-06-09
  • 2014-10-08
  • 2016-07-27
  • 2017-02-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多