Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
How to reference NPM-installed three.js from another NPM-installed library and/or another JS script?

Trying to set up an example of THREE with this MeshLine implementation. Running on VSCode with Live Server extension, port 5500, Firefox. Already tried several combinations of import, require, with or without the type="module" attribute, every time there is a different error. I have the feeling this is because I installed this as NPM modules instead of linking the scripts directly (I did this to be able to use the @types definitions for three), but I just cannot manage to fully understand the JS module ecosystem and variations.

Question
Is it possible to use these libraries (actually three.meshline which requires three) via NPM (= without directly linking the scripts) and if yes, how? Alternatively how to reference NPM three from non-NPM three.meshline script?

/// index.html

<script src="node_modules/three/build/three.module.js"
    type="module"></script>
<!-- <script src="node_modules/three.meshline/src/THREE.MeshLine.js"
    type="module"></script> -->
<script type="module">
    import("./node_modules/three.meshline/src/THREE.MeshLine.js")
</script>


/// THREE.MeshLine.js

;(function() {
  'use strict'

  var root = this
  var has_require = typeof require !== 'undefined'

  console.log(root.THREE)  // undefined
  console.log(has_require) // false

  var THREE = root.THREE || (has_require && require('three')) // <-- Uncaught TypeError: root is undefined
  if (!THREE) throw new Error('MeshLine requires three.js')   // <-- never managed to pass this test

  // (implementation code here)...

  if (typeof exports !== 'undefined') {
    if (typeof module !== 'undefined' && module.exports) {
      exports = module.exports = {
        MeshLine: MeshLine,
        MeshLineMaterial: MeshLineMaterial,
        MeshLineRaycast: MeshLineRaycast,
      }
    }
    exports.MeshLine = MeshLine
    exports.MeshLineMaterial = MeshLineMaterial
    exports.MeshLineRaycast = MeshLineRaycast
  } else {
    root.MeshLine = MeshLine
    root.MeshLineMaterial = MeshLineMaterial
    root.MeshLineRaycast = MeshLineRaycast
  }
}.call(this))
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda