question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing examples jsm modules causes bundlers to bundle three.js source code twice

See original GitHub issue

Importing from three/examples/jsm/.../<module> causes bundlers (tested with rollup) to include the library twice (or multiple times).

For example, when doing import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls', the bundler will follow the import and in the OrbitControls.js the imports come from ../../../build/three.module.js. However, there is no way for the (external) bundler to know that ../../../build/three.module.js is the same module as three.

A solution for this would be to treat the examples modules as external packages and import from three instead of ../../../build/three.module.js. This might break the rollup config of three.js, but it should be possible to tell rollup that three is an alias for the main entry point of three (src/Three.js).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:79 (30 by maintainers)

github_iconTop GitHub Comments

8reactions
mrdoobcommented, Apr 14, 2021

@gkjohnson @donmccurdy

I think I’m all for adopting https://skypack.dev/ and having a script that converts “…/build/three.module.js” to “three” at npm publish time 👍

6reactions
greggmancommented, Oct 7, 2019

I think it’s just something to get used to. Now that I think I get it I’m fine with the way it is.

BTW I updated threejsfundamentals to all be esm based so 🤞

Read more comments on GitHub >

github_iconTop Results From Across the Web

How about making examples/jsm/ all import src/Three.js ...
a current project using “three” and, say, orbitcontrols, can end up with two distinct threejs versions since the bundler only cares about ...
Read more >
Idea: update all modules to not import the entire three.js library
For example, the very first import in OrbitControls.js is this: import ... three imports because the namespaces conflict, the bundle will be twice...
Read more >
Two copies of Three.js were packaged by mistake when I ...
My new bundle is now almost twice the si… I checked the code of RGBELoader and found that it was referenced like this:...
Read more >
JSM modules for browser double import with TypeScript
Sadly this results for me in having three. js twice in my final bundle (at least that's what I think). Gulp with tsify,...
Read more >
In npm why do module imports from examples/jsm use 'three ...
I just upgraded to the latest npm version of three.js - 0.132.2. This causes my app to fail in all browsers with this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found