Skip to content

Issues with dev environment and consuming Node packages #190

@jgaehring

Description

@jgaehring

I've been trying to set up a development environment for adding new controls, behaviors, etc, either as a third-party extension and/or to include in the official repo.

First I tried to simply clone the repo and branch off 2.x to experiment a bit with the examples. To start off, I found the README a bit confusing in the way it describes using the install-all script "in each example project", when the install-all script is not included in each example, but at the root of the examples directory itself. It also doesn't mention that the examples depend upon the distributable version of the library, which needs to be built first.

Those are really minor issues, but ultimately, it all seemed to be in vain, b/c most of the examples require Mapbox API keys to work. I really don't know if the examples are at all intended for this purpose, but if so, it might be helpful to include an OpenStreetMaps example that's a little more sophisticated than the minimal-html-consumer.

The root-level npm run dev script, which is recommended under the README.md#Development, also seems to use the simple-html-consumer example as its base, so this too breaks w/o the Mapbox API keys.

After that I switched tracks, since it seemed like the examples weren't really intended for development, but for the farmos.github.io only. So I initialized a vanilla Vite project with farmOS-map as an dependency consumed via npm. Here I ran into a number of errors, based largely upon the way that the root package.json points to src/index.js as the main entry point, but there seem to be some bugs if not using Webpack and/or a similar configuration as the root webpack.config.js.

One issue was with clusterStyle import, which frankly I don't fully understand, except it might be looking in the wrong node_modules directory, or something to do with the order of the imports, maybe?

✘ [ERROR] No matching export in "node_modules/@farmos.org/farmos-map/src/styles.css" for import "clusterStyle"

    node_modules/@farmos.org/farmos-map/src/instance/methods/layer.js:18:22:
      18 │ import colorStyles, { clusterStyle } from '../../styles';
         ╵                       ~~~~~~~~~~~~

I circumvented this error simply by removing the offending line in my node_modules/.../layer.js for the time being, but then I ran into a separate runtime error with the way the OpenLayers CSS are being imported:

Failed to resolve import "/home/jamie/Code/farmOS/trace-n-point/node_modules/ol/ol.css" from "node_modules/.vite/deps/@farmos__org_farmos-map.js?v=8efa65a3". Does the file exist?

I suspect that this is avoided with the distributable b/c Webpack bundles that CSS and adds the proper script tag to the example index.html or just injects it into the JS bundle itself. The README has some recommendations for this, but I'm not really sure I understand these instructions. It states:

Naturally, this requires that the farmOS-map.js and farmOS-map.css files are already included in the page as described in the Usage instructions above.

But that seems to infer one is consuming farmOS-map.js and farmOS-map.css from dist/, yet the package.json points to src, so that is where most bundlers and Node projects will look for them.

So I guess I'm left with two main questions:

  1. Would it be possible/desirable to add a separate distributable that bundles all the necessary scripts and styles at separate entry points that don't involve attaching the to the global window object, like dist/farmOS-map.js does, but make them more bundler-agnostic and npm-friendly than drawing directly from src/? Something like, say, lib/index.js and lib/index.css?
  2. Are the examples intended to be used for the development environment, or is there a better method? Is it expected that one has their own Mapbox API keys? Or could we add an OpenStreetMap example like I suggested above?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions