Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Rails Stimulus controller use #491

Open
MtnBiker opened this issue Oct 30, 2022 · 1 comment
Open

Problem with Rails Stimulus controller use #491

MtnBiker opened this issue Oct 30, 2022 · 1 comment

Comments

@MtnBiker
Copy link

MtnBiker commented Oct 30, 2022

Rails Stimulus doesn't deal with ol/control/Control, therefore going back to old style which seems to work.

Using node_modules;

import ol from 'openlayers/dist/ol-debug.js'

and then have to use for example var baseLayers = new ol.layer.Group

But
import LayerSwitcher from 'ol-layerswitcher/dist/ol-layerswitcher.js'

has this error

 ✘ [ERROR] Could not resolve "ol/control/Control"

     node_modules/ol-layerswitcher/dist/ol-layerswitcher.js:2:97:
       2 │ ...rts = factory(require('ol/control/Control'), require('ol/Observa...
         ╵                          ~~~~~~~~~~~~~~~~~~~~

   You can mark the path "ol/control/Control" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.

 ✘ [ERROR] Could not resolve "ol/Observable"

     node_modules/ol-layerswitcher/dist/ol-layerswitcher.js:2:128:
       2 │ ...ntrol/Control'), require('ol/Observable'), require('ol/layer/Gro...
         ╵                             ~~~~~~~~~~~~~~~

   You can mark the path "ol/Observable" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.

 ✘ [ERROR] Could not resolve "ol/layer/Group"

     node_modules/ol-layerswitcher/dist/ol-layerswitcher.js:2:154:
       2 │ ...l/Control'), require('ol/Observable'), require('ol/layer/Group')) :
         ╵                                                   ~~~~~~~~~~~~~~~~

   You can mark the path "ol/layer/Group" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.

Any work arounds or? LayerSwitcher is what I need for my app. Thank you

@walkermatt
Copy link
Owner

It looks as though you're using ES Modules to import OpenLayers and the LayerSwitcher but when imported ol-layerswitcher thinks you're using CommonJS hence the attempt to use require.

Do you know why Rails Stimulus doesn't support import Map from 'ol/Map'; etc?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants