I am trying to setup OpenLayers on my computer, and am following the directions here: http://openlayers.org/en/latest/doc/tutorials/bundle.html
When I try to run it in my browser I get error:
import declarations may only appear at top level of a module
How do I fix that?
index.js:
import 'ol/ol.css';
import {Map, View} from 'ol';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
const map = new Map({
target: 'map',
layers: [
new TileLayer({
source: new OSM()
})
],
view: new View({
center: [0, 0],
zoom: 0
})
});
The error clearly states that somewhere in your .js
files there is an import statement:
import something from 'some-package'
And that import statement is not at the very top of the module e.g.:
someExpressionHere(); // This must be moved below import statement
import something from 'some-package'
UPD: After chatting with OP, the actual problem was not building the project (not bundling), when there was a css module import.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With