When I try to compile my web application using Angular 12 and Open layers if I try to compile the code with the line
import GeoTIFF from 'ol/source/GeoTIFF';
I get 2 errors.
Error: node_modules/geotiff/dist-node/geotiffimage.d.ts:67:118 - error TS2304: Cannot find name 'Source'.
This error I resolved by adding an import to ol/source/Source.
the last error I get which I cant find anywhere else online when I search for it is
Error: node_modules/geotiff/dist-node/geotiffimage.d.ts:136:100 - error TS2304: Cannot find name 'AbstractDecoder'.
which I cant find any way to import or any documentation on.
I installed OL with the by npm install ol and npm install @types/ol and its a fresh project from there so I have no idea why I'm getting this error or how to resolve it.
Any advice to resolve this or links to resources would be greatly appreciated
Since the v6.6.0 of OpenLayers, the TS declarations are included in the ol packages, so you don't need to install @types/ol anymore (see the release notes here). Removing the package should solve your problem.
I recommand you as well to set "skipLibCheck": true
in the "compilerOptions"
of your tsconfig.json
, as suggested in this Git issue to avoid further problems with types definitions. Here is an example :
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
},
}