1

I have some simple TypeScript code that uses OpenLayers that I can compile into JavaScript, load into a browser and everything works fine:

var map = new ol.Map({
  target: 'map',
  layers: [new ol.layer.Tile({source: new ol.source.OSM()})],
  view: new ol.View({
    center: [0, 0],
    zoom: 4
  })
});

However as soon as I try to import a second code file into the main file I get an error that I cannot resolve:

import {SomeClass} from "./SomeClass";

var map = new ol.Map({
  // ... save as above

index.ts(3,15): error TS2686: 'ol' refers to a UMD global, but the current file is a module. Consider adding an import instead.

Compiling against OpenLayers types installed like so:

npm install --save-dev openlayers
npm install --save-dev @types/openlayers

How can I compile a TypeScript code base with multiple code files that uses OpenLayers?

1
  • According to Github - OpenLayers, ol needs installing as well. Commented Jun 13, 2018 at 21:06

1 Answer 1

2

Try to use

import * as ol from 'openlayers';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.