简体   繁体   English

尽管软件包报告了相同的版本,但本地 npm package 和 repo 之间怎么能不匹配?

[英]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我刚刚更新了 Angular 8.2.4 -> 9.1.6 和 Typescript 3.4 -> 3.8.3 使用

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.如果我降级到 Typescript 3.7,它们就可以工作,但对于特定的 package,我需要 3.8。

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. 'npm ls request' 显示请求正在 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.如果我 go 到我的本地 node_module/@angular_devkit/build-angular/package.json (v 0.901.6),我看到 ZEFE90A8E604A7C840E88D03A67F6 没有“无”

However, in the package.json of the github for @angular_devkit/build-angular (v 0.901.6), less is not included at all..但是,在 @angular_devkit/build-angular (v 0.901.6) 的 github 的 package.json 中,less 不包括在内。

How can it be that my local copy differs from the github if the versions are the same?如果版本相同,我的本地副本怎么会与 github 不同?

I've tried deleting package-lock and node_modules and reinstalling.我试过删除 package-lock 和 node_modules 并重新安装。

I made a new angular project which defaulted to v8 because of the global cli.我创建了一个新的 angular 项目,由于全局 cli,该项目默认为 v8。 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).我认为问题一定是全局和本地 cli 之间的不匹配(尽管 ng 更新仍在继续,只是注意到它正在使用临时构建进行安装)。 I updated the global cli to 9 and created a new project without the issue.我将全局 cli 更新为 9 并创建了一个没有问题的新项目。

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.但是,从 package.json 中删除这些依赖项、删除节点模块和锁并重新安装并不能修复新项目。

Is there something other than package-lock.json that is retaining the install command for whatever package is messing things up?除了 package-lock.json 之外,还有其他东西保留了安装命令,因为 package 搞砸了?

Angular version info: Angular 版本信息:

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.听起来,您可能已经手动安装了 TypeScript 并弄乱了一些依赖关系树。 I would try reverting your changes and running the upgrade via ng update .我会尝试恢复您的更改并通过ng update运行升级。 FWIW, my 9.1 project has "typescript": "3.7.5" FWIW,我的 9.1 项目有"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.当您运行ng update时,它会为您提供摘要,然后您必须开始一一进行并升级。 Usually the first thing you'll have to do it run:通常你必须做的第一件事就是运行:

ng update @angular/cli @angular/core . 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:另一个很好的故障排除步骤是 go 通过他们的升级表格来确定升级项目需要采取的步骤:

https://update.angular.io/ 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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