Use dynamic imports for non-browser-compatible modules #422
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bit of background: I'm at the Évora OGC-OSGeo-ASF codesprint, trying to get multiband rasters work with gleo via geotiff.js. I wrote gleo so that it worked as native browser ESM modules, via
<script type='module'>
andimportmap
. See e.g. https://gitlab.com/IvanSanchez/gleo/-/blob/master/browser-demos/91-offscreen-indicator.html?ref_type=heads#L19-L40The problems that turn up when trying to run geotiff.js as native ESM modules are pretty much the sames as #411 - a file like
sources/remote.js
unconditionally imports the browser-compatible and the browser-incompatible files (i.e. a file withimport from 'fs'
orimport from 'http'
will crash in a browser).The approach of this fix is to conditionally load those troublesome modules, using dynamic imports. It still works the same, just with a couple more
async
calls.See also DanielJDufour/xml-utils#7