1

当我使用 angular cli update 命令将 angular 项目从 10 更新到 11 时,我在编译时没有出现任何错误,但是当在浏览器上运行我们的网站时,它会显示像这样的错误。

我已经安装和卸载了不同版本的 tslib,但仍然显示错误。

多次删除节点模块,然后运行 ​​npm i , ng update 但得到相同的错误。

错误是

Uncught Error: Cannot find module 'tslib'
at webpackEmptyContext (src sync:2)
at util.js:20
at util.js:10
at Object.Yoyx (util.js:16)
at __webpack_require__ (bootstrap:79)
at Module.WZuZ (leftbar.component.ts:2)
at __webpack_require__ (bootstrap:79)
at Module.J7Q4 (zone.model.ts:79)
at __webpack_require__ (bootstrap:79)
at Module.vY5A (app-routing.module.ts:2)

包.json

{
  "name": "Project Name",
  "version": "0.0.0",
  "scripts": {
     "ng": "ng",
     "start": "ng serve --proxy-config proxy.conf.json",
     "build": "ng build",
     "test": "ng test",
     "lint": "ng lint",
     "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
  "@angular/animations": "^11.1.1",
  "@angular/cdk": "^11.1.1",
  "@angular/common": "~11.1.1",
  "@angular/compiler": "~11.1.1",
  "@angular/core": "^11.1.1",
  "@angular/forms": "~11.1.1",
  "@angular/http": "^7.2.16",
  "@angular/localize": "^11.1.1",
  "@angular/material": "^11.1.1",
  "@angular/platform-browser": "~11.1.1",
  "@angular/platform-browser-dynamic": "~11.1.1",
  "@angular/router": "~11.1.1",
  "@cedx/ngx-webstorage": "^3.7.0",
  "@fortawesome/angular-fontawesome": "^0.4.0",
  "@fortawesome/fontawesome-free-solid": "^5.0.13",
  "@fortawesome/fontawesome-svg-core": "^1.2.34",
  "@fortawesome/free-solid-svg-icons": "^5.15.2",
  "@ng-bootstrap/ng-bootstrap": "^4.2.2",
  "@ng-bootstrap/schematics": "^2.0.0-alpha.1",
  "@types/jquery": "^3.5.5",
  "angular-bootstrap-md": "^7.5.4",
  "angular-image-slider": "0.0.8",
  "angular-popper": "^2.0.1",
  "bn-ng-idle": "^1.0.1",
  "bootstrap": "^4.6.0",
  "core-js": "^2.6.12",
  "file-saver": "^2.0.5",
  "gauge-js": "^1.0.5",
  "html2canvas": "^1.0.0-rc.7",
  "jquery": "^3.5.1",
  "jspdf": "^1.5.3",
  "mqtt": "^3.0.0",
  "multer": "^1.4.2",
  "ng2-file-upload": "^1.4.0",
  "ngx-bootstrap": "^4.3.0",
  "ngx-cookie-service": "^2.4.0",
  "ngx-pagination": "^5.0.0",
  "ngx-ui-loader": "^7.2.2",
  "ngx-webstorage-service": "^4.1.0",
  "phaser": "^3.52.0",
  "popper.js": "^1.16.1",
  "rxjs": "^6.6.3",
  "rxjs-compat": "^6.6.3",
  "tslib": "^2.1.0",
  "worker-plugin": "^3.2.0",
  "zone.js": "~0.10.2"
 },
 "devDependencies": {
 "@angular-devkit/build-angular": "~0.1101.2",
 "@angular/cli": "~11.1.2",
 "@angular/compiler-cli": "~11.1.1",
 "@angular/language-service": "~11.1.1",
 "@fortawesome/fontawesome-free": "^5.15.2",
 "@types/jasmine": "~3.6.0",
 "@types/jasminewd2": "^2.0.8",
 "@types/node": "^12.11.1",
 "codelyzer": "^6.0.0",
 "jasmine-core": "~3.6.0",
 "jasmine-spec-reporter": "~5.0.0",
 "karma": "~5.2.3",
 "karma-chrome-launcher": "~3.1.0",
 "karma-coverage-istanbul-reporter": "~3.0.2",
 "karma-jasmine": "~4.0.0",
 "karma-jasmine-html-reporter": "^1.5.0",
 "protractor": "~7.0.0",
 "ts-node": "~7.0.0",
 "tslint": "~6.1.0",
 "typescript": "~4.0.5"
 },
 "resolutions": {
 "webpack": "^5.0.0"
 }  
}

在那个页面上我有错误

          import { Component, OnInit,EventEmitter } from '@angular/core';
          import { NgForm } from '@angular/forms';
          import { ZoneService } from '../zone.service';
          import {Router} from '@angular/router';
          import {NgxUiLoaderService} from 'ngx-ui-loader';
          import { stringify } from '@angular/compiler/src/util';

          @Component({
            selector: 'app-forgetpass',
            templateUrl: './forgetpass.component.html',
            styleUrls: ['./forgetpass.component.css']
          })
          export class ForgetpassComponent implements OnInit {
            public otp;
            public wrongPassword =  false;
            public otpCheck: boolean = false;
            public  email;
            public otpForm = true;
            public forgetPass = false;
            constructor(private _zoneservice: ZoneService,
                        private router: Router,
                        private ngxLoader: NgxUiLoaderService){ }
            
            ngOnInit(){
              this.ngxLoader.start();
              this.isLogIn()
              this.ngxLoader.stop();
              
            }

          /////////////////to check if user already logged in or not ////////////////

            isLogIn(){
              this._zoneservice.isLogIn().subscribe(data => {
                if(data[0].mssg == 'success'){
                  var username = data[0].username
                  var client = data[0].client;
                  var Cid = data[0].Cid;
                  var image = data[0].image
            
                  // alert(Cid)     
                  //  alert('heh')

                  localStorage.setItem('username',username)
                  localStorage.setItem('Cid',Cid)
                  localStorage.setItem('client',client)
                  localStorage.setItem('Image',image)
                //  console.log('new',localStorage)
                  this.router.navigate(['/brs/home',username,client]);
                }
              })
            }

            ///////////////// for forget password ////////////////////////
          onforget(form: NgForm){
            //  alert("hey")
            var email = form.value.email;
            var user = form.value.user;
            this._zoneservice.forgetpassword(email,user)
            .subscribe
            (
              data=>
              {  
                this.otp = data[0].otp
                // console.log(data[0].mssg);
                console.log(data)
                alert(this.otp);
                
                if(data[0].mssg == "otp_sent"){
                  (<HTMLInputElement>document.getElementById("otp_check")).style.display = "block";
                  (<HTMLInputElement>document.getElementById("otp_sent")).style.display = "none";
                  this.otpForm=  true;
                  //  alert('redirect')
                  // this.router.navigate(['/forget_password'])
                  
                }
                
              })
            
              }
              
                ///////////////// for otp check ////////////////////
              otp_check(form: NgForm){
                  //  alert("email");
                var enteredOtp = form.value.otp;
              this.email = (<HTMLInputElement>document.getElementById("email")).value;
              //  alert(email);
              //  alert(enteredOtp);
              //  alert(this.otp);
              if(enteredOtp==this.otp){
                this.otpCheck =  true
                //this.router.navigate(['/forget_password']);

              }

              }


              //////////////////    for setting new password //////////////////////
              change_pass(form: NgForm){
                  
              var password = form.value.password;
              var Confirm_password = form.value.Confirm_password;

              if(password == Confirm_password){
              
                this._zoneservice.changepassone(password,this.email)
              .subscribe
              (
                data=>
                { 
                  //  console.log(data);
                  if(data[0].mssg == "success"){
                  //  alert('Password Change');
                    this.router.navigate(['']);
                  }
                  else{
                    alert('Some Error!');
                  }
                })
              }
              else{
                alert("Password And Confirm Password doesn't match.")
              }
              }


              ///////////////// for login //////////////////////
            
            onLogin(form: NgForm){

            var result ;
            var email : string;
          var password = '';
          var username = '';
          var client : string;
          var Cid:any;
          var image : string;
          var loginValidate = new EventEmitter();
            // alert(form.value.username);
            if(form.invalid){
              return;
            }
            const loginData = {
              username:form.value.username,
              password: form.value.password
            };
            //console.log(loginData);
            this._zoneservice.login(loginData)
            .subscribe
            (
              data=>
              {
                result = data;
              // console.log(result);
                if(result[0].mssg == "Success"){
                  username = result[0].username;
                  image = result[0].image;
                  client = result[0].client;
                  Cid = result[0].Cid;
                //  console.log(result[0])
                  var cur_date = new Date();
                localStorage.setItem('username',username);
                localStorage.setItem('image',image);
                localStorage.setItem('Cid',Cid);
                localStorage.setItem('client',client);
                localStorage.setItem('op_start',''+cur_date.getTime());
                localStorage.setItem('LoginTime', stringify(cur_date));
                console.log(stringify(cur_date));
                //console.log(localStorage)
              // alert(username);

                  this.router.navigate(['/brs/home',username,client]);
                //  alert(image)
                }
                else{
                  this.wrongPassword = true;
                  this.router.navigate([''])

                }
              }
            )


          }
            
            //////////////////for opening forget password  ///////////// 

          forgetPassButton(){
            this.forgetPass= true;
          // this.router.navigate(['/forget_password']);
            
          }

          }
4

1 回答 1

1

您需要避免使用import { stringify } from '@angular/compiler/src/util';. 通常,当您尝试使用来自@angular/compiler. 可能您需要使用angular.toJsonorangular.fromJson而不是stringify .

于 2021-07-09T09:08:45.413 回答