visgl / deck.gl

WebGL2 powered visualization framework
https://deck.gl
MIT License
12.25k stars 2.08k forks source link

[Bug] package.json incorrectly configured for ESM #8186

Closed keller-mark closed 1 year ago

keller-mark commented 1 year ago

Description

Hi, I am using DeckGL in my web application. I am running into issues when importing DeckGL (directly or indirectly) in unit testing frameworks which execute code using NodeJS (vitest in particular) because the package.json for deck.gl (as well as for @deck.gl/*):

This is also clear when checking deck.gl in Publint: https://publint.dev/deck.gl@8.9.30

This issue might not have previously been reported if all DeckGL sub-dependencies had CJS equivalents. However it appears that relatively recently at least one sub-dependency (@mapbox/tiny-sdf) is published as ESM-only which is causing this issue to be detected.

Flavors

Expected Behavior

Expect either:

OR

Also, expect Publint to pass without warnings/errors.

Also, expect exports field of package.json to be defined for usage by NodeJS.

Steps to Reproduce

https://stackblitz.com/edit/vitejs-vite-fxr3cz?file=src%2Fdeckgl.test.js

Environment

Logs

 FAIL  src/deckgl.test.js [ src/deckgl.test.js ]
Error: require() of ES Module /home/projects/vitejs-vite-fxr3cz/node_modules/@mapbox/tiny-sdf/index.js from /home/projects/vitejs-vite-fxr3cz/node_modules/@deck.gl/layers/dist/es5/text-layer/font-atlas-manager.js not supported.
Instead change the require of index.js in /home/projects/vitejs-vite-fxr3cz/node_modules/@deck.gl/layers/dist/es5/text-layer/font-atlas-manager.js to a dynamic import() which is available in all CommonJS modules.
 ❯ makeNodeErrorWithCode/< ../../../blitz.7a1fe16d.js:36:4174
 ❯ Module."] ../../../blitz.7a1fe16d.js:55:15296
 ❯ Module.prototype.load ../../../blitz.7a1fe16d.js:55:13469
 ❯ Module._load ../../../blitz.7a1fe16d.js:55:10541
 ❯ Module.prototype.require ../../../blitz.7a1fe16d.js:55:13787
 ❯ i ../../../blitz.7a1fe16d.js:98:2198
 ❯ _0x5b8ff6 ../../../blitz.7a1fe16d.js:355:176557
 ❯ function ../../../blitz.7a1fe16d.js:355:177359
 ❯ Module.prototype._compile ../../../blitz.7a1fe16d.js:55:14883
 ❯ Module."] ../../../blitz.7a1fe16d.js:55:15564
 ❯ Module.prototype.load ../../../blitz.7a1fe16d.js:55:13469
 ❯ Module._load ../../../blitz.7a1fe16d.js:55:10541
 ❯ Module.prototype.require ../../../blitz.7a1fe16d.js:55:13787
 ❯ i ../../../blitz.7a1fe16d.js:98:2198
 ❯ _0x5b8ff6 ../../../blitz.7a1fe16d.js:355:176557
 ❯ function ../../../blitz.7a1fe16d.js:355:177359
 ❯ Module.prototype._compile ../../../blitz.7a1fe16d.js:55:14883
 ❯ Module."] ../../../blitz.7a1fe16d.js:55:15564
 ❯ Module.prototype.load ../../../blitz.7a1fe16d.js:55:13469
 ❯ Module._load ../../../blitz.7a1fe16d.js:55:10541
 ❯ Module.prototype.require ../../../blitz.7a1fe16d.js:55:13787
 ❯ i ../../../blitz.7a1fe16d.js:98:2198
 ❯ _0x5b8ff6 ../../../blitz.7a1fe16d.js:355:176557
 ❯ function ../../../blitz.7a1fe16d.js:355:177359
 ❯ Module.prototype._compile ../../../blitz.7a1fe16d.js:55:14883
 ❯ Module."] ../../../blitz.7a1fe16d.js:55:15564
 ❯ Module.prototype.load ../../../blitz.7a1fe16d.js:55:13469
 ❯ Module._load ../../../blitz.7a1fe16d.js:55:10541
 ❯ Module.prototype.require ../../../blitz.7a1fe16d.js:55:13787
 ❯ i ../../../blitz.7a1fe16d.js:98:2198
 ❯ _0x5b8ff6 ../../../blitz.7a1fe16d.js:355:176557
 ❯ function ../../../blitz.7a1fe16d.js:355:177359
 ❯ Module.prototype._compile ../../../blitz.7a1fe16d.js:55:14883
 ❯ Module."] ../../../blitz.7a1fe16d.js:55:15564
 ❯ Module.prototype.load ../../../blitz.7a1fe16d.js:55:13469
 ❯ Module._load ../../../blitz.7a1fe16d.js:55:10541
 ❯ Module.prototype.require ../../../blitz.7a1fe16d.js:55:13787
 ❯ i ../../../blitz.7a1fe16d.js:98:2198
 ❯ _0x5b8ff6 ../../../blitz.7a1fe16d.js:355:176557
 ❯ function ../../../blitz.7a1fe16d.js:355:177359
 ❯ Module.prototype._compile ../../../blitz.7a1fe16d.js:55:14883
 ❯ Module."] ../../../blitz.7a1fe16d.js:55:15564
 ❯ Module.prototype.load ../../../blitz.7a1fe16d.js:55:13469
 ❯ Module._load ../../../blitz.7a1fe16d.js:55:10541
 ❯ Module.prototype.require ../../../blitz.7a1fe16d.js:55:13787
 ❯ i ../../../blitz.7a1fe16d.js:98:2198
 ❯ _0x5b8ff6 ../../../blitz.7a1fe16d.js:355:176557
 ❯ function ../../../blitz.7a1fe16d.js:355:177359
 ❯ Module.prototype._compile ../../../blitz.7a1fe16d.js:55:14883
 ❯ Module."] ../../../blitz.7a1fe16d.js:55:15564
 ❯ Module.prototype.load ../../../blitz.7a1fe16d.js:55:13469
 ❯ Module._load ../../../blitz.7a1fe16d.js:55:10541
 ❯ _evaluate ../../../blitz.7a1fe16d.js:355:352285
 ❯ evaluate ../../../blitz.7a1fe16d.js:355:351379
 ❯ run ../../../blitz.7a1fe16d.js:181:2390

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { fileName: 'https://vitejsvitefxr3cz-iwb0.w-corp.staticblitz.com/blitz.7a1fe16d.js', lineNumber: 64, columnNumber: 14437, code: 'ERR_REQUIRE_ESM' }
keller-mark commented 1 year ago

Related to https://github.com/mapbox/tiny-sdf/issues/53 (I believe the DeckGL package.json are the root issue, not the @mapbox/tiny-sdf package.json)

Pessimistress commented 1 year ago

deck.gl v8.x is not a ESM module, i.e. you cannot import it directly in Nodejs. This is not a bug.

Refer to #8187 for v9.0 plans.

keller-mark commented 1 year ago

Hi @Pessimistress, thanks for the information. It appears the link to the v9 plans is broken, would you be able to share a new link?

Pessimistress commented 1 year ago

It's just a link to the other issue you created.

keller-mark commented 1 year ago

Ah sorry for the confusion, I was expecting a v9 roadmap - is that type of document/issue available?

donmccurdy commented 7 months ago

v9 has been published with "type": "module" and a package.json#exports entry:

https://unpkg.com/@deck.gl/core@9.0.1/package.json

Related: