简体   繁体   中英

How can you have a mismatch between a local npm package and repo though the packages report same version?

I just updated Angular 8.2.4 -> 9.1.6 and Typescript 3.4 -> 3.8.3 using

ng update @angular/cli @angular/core

I've got a number of module imports that are now breaking. They work if I downgrade to Typescript 3.7 but I need 3.8 for a particular package.

The specific module import error I'm delving into here:

Module not found: Error: Can't resolve 'zlib' in '<project>/pangeav4/node_modules/request'

An 'npm ls request' shows request is being used in the dependencies of Angular 9.1.6.

├─┬ @angular-devkit/build-angular@0.901.6
│ └─┬ less@3.11.1
│   └── request@2.88.2 
├─┬ @angular/cli@9.1.6
│ └─┬ universal-analytics@0.4.20
│   └── request@2.88.2  deduped

And if I go to my local node_module/@angular_devkit/build-angular/package.json (v 0.901.6), I see the package "less" is a dependency.

However, in the package.json of the github for @angular_devkit/build-angular (v 0.901.6), less is not included at all..

How can it be that my local copy differs from the github if the versions are the same?

I've tried deleting package-lock and node_modules and reinstalling.

I made a new angular project which defaulted to v8 because of the global cli. I figured the issue must be a mismatch between the global and local cli (though the ng update continues and just notes that it is using a temp build for the install). I updated the global cli to 9 and created a new project without the issue.

Once I added the dependencies from the existing project, the issue returned. However, removing those dependences from the package.json, deleting node modules and the lock, and reinstalling did not fix the new project.

Is there something other than package-lock.json that is retaining the install command for whatever package is messing things up?

Angular version info:

Angular CLI: 9.1.6
Node: 10.18.0
OS: darwin x64

Angular: 9.1.9
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Ivy Workspace: No

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.801.3
@angular-devkit/build-angular     0.901.6
@angular-devkit/build-optimizer   0.901.6
@angular-devkit/build-webpack     0.901.6
@angular-devkit/core              9.1.6
@angular-devkit/schematics        9.1.6
@angular/cdk                      9.2.4
@angular/cli                      9.1.6
@angular/fire                     5.4.2
@angular/material                 9.2.4
@ngtools/webpack                  9.1.6
@schematics/angular               9.1.6
@schematics/update                0.901.6
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.43.0

From what it sounds like, you might have installed TypeScript manually and messed up some dependency tree. I would try reverting your changes and running the upgrade via ng update . FWIW, my 9.1 project has "typescript": "3.7.5"

When you run ng update , it will give you the summary and then you have to start going through and upgrading things one by one. Usually the first thing you'll have to do it run:

ng update @angular/cli @angular/core . You don't want to specify any version here unless you're targeting something specific. It will grab the latest version by default.

One other good troubleshooting step is to go through their upgrade form to determine what steps you need to take in order to upgrade your project:

https://update.angular.io/

Angular CLI: 9.1.4
Node: 10.16.2
OS: darwin x64

Angular: 9.1.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.7
@angular-devkit/build-angular     0.900.7
@angular-devkit/build-optimizer   0.900.7
@angular-devkit/build-webpack     0.900.7
@angular-devkit/core              9.0.7
@angular-devkit/schematics        9.1.4
@angular/cdk                      9.2.2
@angular/cli                      9.1.4
@angular/material                 9.2.2
@ngtools/webpack                  9.0.7
@schematics/angular               9.1.4
@schematics/update                0.901.4
rxjs                              6.5.5
typescript                        3.7.5
webpack                           4.41.2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM