Angular 8 包:TS1086 编译错误,skipLibCheck 30+ 库

huangapple go评论76阅读模式
英文:

Angular 8 packages: TS1086 Error compilation, skipLibCheck 30+ library

问题

我在Angular中编译一个库时遇到了问题。当我运行ng build命令时出现了错误。

如果您在tsconfig中添加skipLibCheck: true,错误将消失。

但是Openlayers是一个单独的包依赖项。这个包与其他库一起提供。(假设总共有30个包。)

当Openlayers作为其他包的依赖项安装时,就会出现这个错误。

是否可能在其他30个包中避免设置skipLibCheck: true

英文:

I have a problem compiling a library in angular. The error appears when I run the ng build command

ERROR: node_modules/ol/MapBrowserEvent.d.ts(47,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ol/MapBrowserEvent.d.ts(53,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ol/MapBrowserEvent.d.ts(54,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ol/MapBrowserEvent.d.ts(61,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ol/View.d.ts(582,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ol/View.d.ts(592,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ol/Map.d.ts(404,22): error TS2304: Cannot find name 'ResizeObserver'.
node_modules/ol/webgl/Buffer.d.ts(13,14): error TS2303: Circular definition of import alias 'STATIC_DRAW'.
node_modules/ol/webgl/Buffer.d.ts(14,14): error TS2303: Circular definition of import alias 'STREAM_DRAW'.
node_modules/ol/webgl/Buffer.d.ts(15,14): error TS2303: Circular definition of import alias 'DYNAMIC_DRAW'.
node_modules/ol/webgl/Helper.d.ts(36,14): error TS2303: Circular definition of import alias 'UNSIGNED_BYTE'.
node_modules/ol/webgl/Helper.d.ts(37,14): error TS2303: Circular definition of import alias 'UNSIGNED_SHORT'.
node_modules/ol/webgl/Helper.d.ts(38,14): error TS2303: Circular definition of import alias 'UNSIGNED_INT'.
node_modules/ol/webgl/Helper.d.ts(39,14): error TS2303: Circular definition of import alias 'FLOAT'.
node_modules/@types/geojson/index.d.ts(79,13): error TS2456: Type alias 'Geometry' circularly references itself.
node_modules/ol/Geolocation.d.ts(9,24): error TS2304: Cannot find name 'GeolocationPositionError'.
node_modules/ol/format/EsriJSON.d.ts(2,38): error TS2307: Cannot find module 'arcgis-rest-api'.
node_modules/ol/format/EsriJSON.d.ts(3,41): error TS2307: Cannot find module 'arcgis-rest-api'.
node_modules/ol/format/EsriJSON.d.ts(4,39): error TS2307: Cannot find module 'arcgis-rest-api'.
node_modules/ol/format/EsriJSON.d.ts(5,36): error TS2307: Cannot find module 'arcgis-rest-api'.
node_modules/ol/format/EsriJSON.d.ts(6,39): error TS2307: Cannot find module 'arcgis-rest-api'.
node_modules/ol/format/EsriJSON.d.ts(7,38): error TS2307: Cannot find module 'arcgis-rest-api'.
node_modules/ol/format/EsriJSON.d.ts(8,41): error TS2307: Cannot find module 'arcgis-rest-api'.
node_modules/ol/format/EsriJSON.d.ts(9,36): error TS2307: Cannot find module 'arcgis-rest-api'.
node_modules/ol/format/EsriJSON.d.ts(10,39): error TS2307: Cannot find module 'arcgis-rest-api'.
node_modules/ol/format/EsriJSON.d.ts(11,51): error TS2307: Cannot find module 'arcgis-rest-api'.
node_modules/ol/format/EsriJSON.d.ts(28,31): error TS2307: Cannot find module 'arcgis-rest-api'.
node_modules/ol/format/TopoJSON.d.ts(2,39): error TS2307: Cannot find module 'topojson-specification'.
node_modules/ol/format/TopoJSON.d.ts(3,49): error TS2307: Cannot find module 'topojson-specification'.
node_modules/ol/format/TopoJSON.d.ts(4,39): error TS2307: Cannot find module 'topojson-specification'.
node_modules/ol/format/TopoJSON.d.ts(5,36): error TS2307: Cannot find module 'topojson-specification'.
node_modules/ol/format/TopoJSON.d.ts(6,41): error TS2307: Cannot find module 'topojson-specification'.
node_modules/ol/format/TopoJSON.d.ts(7,41): error TS2307: Cannot find module 'topojson-specification'.
node_modules/ol/format/TopoJSON.d.ts(8,46): error TS2307: Cannot find module 'topojson-specification'.
node_modules/ol/format/TopoJSON.d.ts(9,38): error TS2307: Cannot find module 'topojson-specification'.
node_modules/ol/format/TopoJSON.d.ts(10,43): error TS2307: Cannot find module 'topojson-specification'.
node_modules/geotiff/dist-node/source/basesource.d.ts(22,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/geotiff/dist-node/dataslice.d.ts(7,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/geotiff/dist-node/dataslice.d.ts(8,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/geotiff/dist-node/dataslice.d.ts(9,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/geotiff/dist-node/dataslice.d.ts(10,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/geotiff/dist-node/dataslice.d.ts(11,9): error TS1086: An accessor cannot be declared in an ambient context.

If you add skipLibCheck: true to tsconfig, the error will disappear

BUT

Openlayers is a single package dependency. This package is supplied with the rest of the libraries. (Let's assume a total of 30 packages.)

And this error appears where openlayers is installed as a dependency of another package.

Is it possible to avoid setting skipLibCheck: true in the other 30 packages

答案1

得分: 0

  • 首先,我尝试安装 arcgis-rest-api topojson-specification 类型

这并没有解决问题,因为在 OpenLayers 的 d.ts 文件中存在许多错误

  • 要将所有我的库转换为 Angular 9 及以上版本是不可能的(需要大量工作)

问题出在 OpenLayers 生成的几个 d.ts 文件上。我认为总体错误在于 TypeScript 版本之间的不兼容性(Angular 8 = 3.5.3,OpenLayers 7 = 5.0),导致了为 ts 3.5.3 生成带有错误的 d.ts 文件

我创建了一个 OpenLayers 7 的分支,编写了一个 CLI 脚本,用于在所有实体的所有 d.ts 文件中插入 ts-ignore 注释。在构建 ol 之后,我运行我的脚本并发布它。

然后,我在分发 OpenLayers 依赖项的库中用我的分支替换了 ol

总之,现在所有我的库都可以在没有 d.ts 错误的情况下构建。(我没有丢失任何类型信息)

英文:
  • First I tried to install arcgis-rest-api topojson-specification types

This does not solve the problem, as there are a lot of errors in the d.ts openlayers d.ts files themselves

  • To translate all my libraries to angular 9 and above, is impossible (a lot of work to do)

The problem is several d.ts files that openalyers generates. I believe that in general the error lies between versions of TypeScript (Angular 8 = 3.5.3, Openlayers 7 = 5.0) due to incompatibility of ts version, d.ts with errors for ts 3.5.3 are generated

I made a fork of openalyers 7, wrote a cli script that inserts ts-ignore comments in all entities, in all d.ts files. After building ol I apply my script and make a release.

Then I replaced in the libraries that distribute the ol dependency with my fork.

Bottom line: all my libraries are now built without d.ts errors. (I have not lost any typing)

huangapple
  • 本文由 发表于 2023年6月8日 08:27:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76427893.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定