Skip to content

Conversation

@Pessimistress
Copy link

Related: #444

The package will support the following usage in Node:

await import('gl-matrix') await import('gl-matrix/mat4') require('gl-matrix') require('gl-matrix/mat4')

by making the following changes to the published package.json:

+ "type": "module", - "main": "cjs/index.js", + "main": "cjs/index.cjs", "module": "esm/index.js", + "exports": { + ".": { + "require": "./cjs/index.cjs", + "import": "./esm/index.js" + }, + "./mat2": { + "require": "./cjs/mat2.cjs", + "import": "./esm/mat2.js" + }, + "./mat2d": { + "require": "./cjs/mat2d.cjs", + "import": "./esm/mat2d.js" + }, + ...
@donmccurdy
Copy link

Related:

I've been using gl-matrix in a library that is going ESM-only and needs to support Node.js, so my workaround for the time being is to configure my build tool (microbundle) to inline the gl-matrix functions I need, rather than keeping the gl-matrix npm package as a production dependency. This is working for now, but I do look forward to full ESM support and package#exports in v4, if that's still the plan!

@ibgreen
Copy link

ibgreen commented Jan 30, 2023

In the same vein, we are about upgrade math.gl 4.0 to type: module and unless this (or something equivalent) lands, we will need to replace our gl-matrix dependency with a local fork (at least temporarily).

@mikeymaxdb
Copy link

I'm building my project on v4 and it would be awesome to just import from 'gl-matrix' instead of from 'gl-matix/dist/esm'!

@lkmill
Copy link
Contributor

lkmill commented Jul 30, 2023

This should probably not be merged into the 3.4.x branch, as it would be a breaking change.

Full ESM support (including package exports) was merged in #432 and released in version 3.4.0, but reversed in 3.4.{1,2,3} (due to #439). The ESM related changes seem to remain in the master branch, but I'm not sure what the release plan is there. Perhaps @toji or @stefnotch knows more...

@birkskyum
Copy link

birkskyum commented Sep 28, 2025

Hit this as well - working on ESM support / rolldown bundling for maplibre-gl-js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

7 participants