walkermatt / ol-layerswitcher

Layer control for OpenLayers
MIT License
384 stars 176 forks source link

Using ol-layerswitcher with Rollup #492

Open sk-zk opened 1 year ago

sk-zk commented 1 year ago

I'm having some difficulty importing the npm module with Rollup. This is the error message I'm getting:

main.js → dist/main.js...
(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en/#error-this-is-undefined
node_modules/ol-layerswitcher/dist/ol-layerswitcher.js
3:   typeof define === 'function' && define.amd ? define(['ol/control/Control', 'ol/Observable', 'ol/layer/Group'], factory) :
4:   (global.LayerSwitcher = factory(global.ol.control.Control,global.ol.Observable,global.ol.layer.Group));
5: }(this, (function (Control,ol_Observable,LayerGroup) { 'use strict';
     ^
6:
7: Control = 'default' in Control ? Control['default'] : Control;
[!] Error: 'default' is not exported by node_modules/ol-layerswitcher/dist/ol-layerswitcher.js, imported by main.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
main.js (10:7)
 8: import OSM from 'ol/source/OSM.js';
 9:
10: import LayerSwitcher from 'ol-layerswitcher';
           ^
11:
12: const map = new Map({
Error: 'default' is not exported by node_modules/ol-layerswitcher/dist/ol-layerswitcher.js, imported by main.js
    at error (C:\Users\_\AppData\Roaming\npm\node_modules\rollup\dist\shared\rollup.js:198:30)
    at Module.error (C:\Users\_\AppData\Roaming\npm\node_modules\rollup\dist\shared\rollup.js:12560:16)
    at Module.traceVariable (C:\Users\_\AppData\Roaming\npm\node_modules\rollup\dist\shared\rollup.js:12919:29)
    at ModuleScope.findVariable (C:\Users\_\AppData\Roaming\npm\node_modules\rollup\dist\shared\rollup.js:11571:39)
    at Identifier.bind (C:\Users\_\AppData\Roaming\npm\node_modules\rollup\dist\shared\rollup.js:7570:40)
    at NewExpression.bind (C:\Users\_\AppData\Roaming\npm\node_modules\rollup\dist\shared\rollup.js:5400:23)
    at VariableDeclarator.bind (C:\Users\_\AppData\Roaming\npm\node_modules\rollup\dist\shared\rollup.js:5400:23)
    at VariableDeclaration.bind (C:\Users\_\AppData\Roaming\npm\node_modules\rollup\dist\shared\rollup.js:5396:73)
    at Program.bind (C:\Users\_\AppData\Roaming\npm\node_modules\rollup\dist\shared\rollup.js:5396:73)
    at Module.bindReferences (C:\Users\_\AppData\Roaming\npm\node_modules\rollup\dist\shared\rollup.js:12556:18)

Here's my code: https://github.com/sk-zk/ol-ls-rollup