文章目录

  • 背景
  • 最小重现的排查过程
  • 最后

背景

这是一个多种因素综合导致的bug,排查问题花了一些时间,特别是版本9.1.09.1.1这种小版本号的差别导致不同的运行结果容易被忽视。

某个部署环境之前的用于编译的Angular的版本是9.1.0,项目路径是硬链接。编译正常,整理存储时,改成了软链接,编译就失败了。而开发机上编译正常,改用软链接也在开发机上测试过,因此在开始调研的时候就忽视了这个问题。调查的弯路就略过了,整理一个最小重现的情况。

最小重现的排查过程

@angular/compiler-cli的版本为9.1.0是,也就是package.json中为:

"@angular/compiler-cli": "9.1.0",

运行编译命令

yarn run build

可以看到编译7个目标

                     Compiling @angular/core : es2015 as esm2015Compiling @angular/common : es2015 as esm2015Compiling @angular/platform-browser : es2015 as esm2015Compiling @angular/platform-browser-dynamic : es2015 as esm2015Compiling @angular/common/http : es2015 as esm2015Compiling @angular/router : es2015 as esm2015Compiling @nguniversal/common : es2015 as esm2015

然后就是报错

    ERROR in ./node_modules/@angular/common/http/http.d.ts:2801:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.This likely means that the library (@angular/common/http) which declares HttpClientModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.2801 export declare class HttpClientModule {~~~~~~~~~~~~~~~~

其中IvyAngular的编译引擎,从版本9开始作为默认选项,在这里花了很长时间看文档,没有找到有针对性的资料。加之之前一直认为node_modules中只是下载的包,所以开始调查的时候没有看node_modules里面,后来比较细致调查的时候,翻看里面的文件,发现这个文件夹:

./node_modules/@angular/core/__ivy_ngcc__

这时候才注意到Ivy是把中间结果编译在这里,之前一直想当然的认为可能是在某个临时文件夹中。

然后按照编译目标逐个对照发现

./node_modules/@angular/common/__ivy_ngcc__

仅包含common

                         └── fesm2015├── common.js└── common.js.map

而开发机上还包含http.jshttp.js.map

                     └── fesm2015├── common.js├── common.js.map├── http.js└── http.js.map

少编译了一个目标,然而并没有在这个环节报错,因此在后面的环节报错时,就被误导了一直在后面绕圈。

发现问题后,就逐步缩小差异,最后定位到了@angular/compiler-cli版本,当版本为9.1.0时,报错如前所示。升级到9.1.1后,尽管只是最小的版本号,http.jshttp.js.map两个文件出现了,编译也正常了。翻了一下Angular 9.1.1的发布说明,2020年4月7日,这个时间点正好是部署环境升级到了9.1.0,而开发机后来又自动升级,因而导致结果不一致。如果两边都出错的话,也就不会这么大费周章了。

9.1.1 (2020-04-07)
Bug Fixes
compiler: avoid undefined expressions in holey array (#36343) (90cae34)
compiler: resolve enum values in binary operations (#36461) (cbc25bb), closes #35584
compiler-cli: pass real source spans where they are empty (#31805) (4894220)
core: avoid migration error when non-existent symbol is imported (#36367) (dff52ec), closes #36346
core: ngOnDestroy on multi providers called with incorrect context (#35840) (af42694), closes #35231
core: run APP_INITIALIZERs before accessing LOCALE_ID token in Ivy TestBed (#36237) (5c28af0), closes #36230
core: undecorated-classes-with-decorated-fields migration does not decorate derived classes (#35339) (5ff5a11), closes #34376
core: undecorated-classes migration should handle derived abstract classes (#35339) (a631b99)
language-service: infer type of elements of array-like objects (#36312) (ff523c9), closes #36191
language-service: use the HtmlAst to get the span of HTML tag (#36371) (ffa4e11)
ngcc: add process title (#36448) (136596d), closes /github.com/angular/angular/issues/36414#issuecomment-609644282
ngcc: allow ngcc configuration to match pre-release versions of packages (#36370) (cb0a2a0)
ngcc: correctly detect imported TypeScript helpers (#36284) (879457c), closes #36089
ngcc: correctly identify relative Windows-style import paths (#36372) (0daa488)
ngcc: correctly identify the package path of secondary entry-points (#36249) (e53b686), closes #35747
ngcc: detect non-emitted, non-imported TypeScript helpers (#36418) (93b32d3)
ngcc: do not spawn more processes than intended in parallel mode (#36280) (6ea232e), closes #35719 #36278 /github.com/angular/angular/blob/b8e9a30d3b6/packages/compiler-cli/ngcc/src/main.ts#L429 /github.com/angular/angular/blob/b8e9a30d3b6/packages/compiler-cli/ngcc/src/execution/cluster/master.ts#L108 /github.com/angular/angular/blob/b8e9a30d3b6/packages/compiler-cli/ngcc/src/execution/cluster/master.ts#L110 /github.com/angular/angular/blob/b8e9a30d3b6/packages/compiler-cli/ngcc/src/execution/cluster/master.ts#L199
ngcc: do not write entry-point manifest outside node_modules (#36299) (bb8744d), closes #36296
ngcc: don't crash on cyclic source-map references (#36452) (56af303), closes #35727 #35757
ngcc: handle bad path mappings when finding entry-points (#36331) (7bb3588), closes #36313 #36283
ngcc: handle entry-points within container folders (#36305) (392ef93), closes #35756 #36216
ngcc: sniff main property for ESM5 format (#36396) (93cbef2), closes #35788
ngcc: support ignoring deep-imports via package config (#36423) (31eaf78), closes #35750
ngcc: support simple browser property in entry-points (#36396) (b0d680d), closes #36062
platform-server: update xhr2 dependency (#36366) (14ae3c0), closes #36358
router: state data missing in routerLink (#36462) (0e7a89a), closes #33173

最后

尽管问题解决了,但是对照了如上所述的Angular 9.1.1的发布说明,仍旧没有找到是哪条修正了这个问题。
前端是一个神奇的领域,已经开始踩当月的坑了,现在特别能理解前端同学为什么会喊学不动了。

Angular 9.1.0在项目路径包含软链接时编译某些包时报错,9.1.1已修正相关推荐

  1. Windows中的命令行提示符里的Start命令执行路径包含空格时的问题

    转自:http://www.x2009.net/articles/windows-command-line-prompt-start-path-space.html 当使用Windows 中的命令行提 ...

  2. 项目中引用NG-ZORRO,在使用nz-form时报错Can't bind to 'formGroup' since it isn't a known property of 'form'的解决方案

    项目中引用NG-ZORRO,在使用nz-form时报错 Can't bind to 'formGroup' since it isn't a known property of 'form' comp ...

  3. fastjson转换包含date类型属性的对象时报错com.alibaba.fastjson.JSONException: For input string 解决方法

    fastjson转换包含date类型属性的对象时报错com.alibaba.fastjson.JSONException: For input string 解决方法 pojo里面的date属性上要加 ...

  4. centos7创建asm磁盘_asm磁盘路径包含混合路径时的设置

    如果asm磁盘发现路径中,既有udev方式创建的磁盘,又有asmlib创建的磁盘,那么,在asm_diskstring中,需要把两种情况都设置: asm_diskstring string /dev/ ...

  5. android运行jar文件路径,java命令行执行jar包报错解决

    今天遇到一个问题,在终端doc命令行下,执行java -jar 操作,报错Error: Unable to access jarfile CheckAndroidV2Signature.jar 找了各 ...

  6. Jmeter4.0分布式测试时启动Jmeter.server时报错

       最近又开始研究Jmeter,将新版本4.0下载下来体验,准备远程分布式测试,又出现一些问题,废话不多说,直入主题把! Windows 系统启动Jmeter 4.0的JmeterServer.ba ...

  7. Maven项目在eclipse中使用junit进行单元测试时报错:ClassNotFoundException

    Maven项目在eclipse中使用junit进行单元测试时Coonsole出现以下错误: Class not found boco.ips.data.ice.orm.mapper.TestDemoM ...

  8. Ubuntu 20.04.2.0 LTS 下利用Geany 1.36编译C++程序报错“/bin/sh: 1: g++: not found”

    [问题描述] Ubuntu 20.04.2.0 LTS 下利用 sudo apt-get install geany 命令安装Geany 1.36后,利用Geany 1.36写C++语言程序后,单击G ...

  9. Springboot2.0 集成 Elasticsearch 6.x 未添加 transport-netty4-client 依赖 启动时报错

    报错内容关键部分: Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method ...

最新文章

  1. Admin注册和路由分发详解
  2. 安装erlang没有bin文件夹_Centos7安装RabbitMQ(Centos6 此方案同样可行)
  3. [leetcode]102.二叉树的层序遍历
  4. teamcity_TeamCity工件:HTTP,Ant,Gradle和Maven
  5. java j2ssh替代jsch,jsch设置ssh协商算法优先级
  6. 当了几年程序员,是时候考虑以后的发展了
  7. linux下访问西门子S7,Siemens SIMATIC S7-1200 CPU开放重定向漏洞(CVE-2015-1048)
  8. 基金学习20190802
  9. 网络语音视频技术浅议(附多个demo源码下载)
  10. 你真的了解企业虚拟化吗?
  11. C++QT开发——Xml、Json解析
  12. python 算24 代码
  13. iOS 16 NSTextContentStorage locationFromLocation:withOffset: 崩溃问题
  14. rancher 企业级容器管理平台
  15. 1-3 js基础还是看caicia吧(老师说小游戏)
  16. adb自动化控制手机工具类
  17. 统计自然语言处理基础-第四章 基于语料库的工作(笔记)
  18. 西班牙的计算机水平如何,西班牙人的真实英语水平是欧洲国家中最差的吗?
  19. 学习日志 - Openwrt安装python然后wallproxy
  20. python中符号 ~ 的意义和用法

热门文章

  1. 2017年全球FinTech变革全景揭秘及前景展望
  2. java 执行长事物_狂 热 和 许 诺
  3. 算法001-C++从0到1实现链表v1
  4. 【详解---彻底卸载电脑上面Adobe软件】
  5. 实战中icon 的使用
  6. 自定义Group,解决Group setVisibility后,子View再次设置setVisibility无效的问题
  7. 【Unity3D 教程系列第 10 篇】Unity 脚本中的生命周期流程图
  8. python安装第三方库错误No matching distribution found for cfg
  9. 前往美孚主义2013
  10. Oracle EBS WIP任务单批量发料功能开发