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

301
Vistas
Uncaught ReferenceError: require is not defined (How to use a javascript library from the command line, or an html file)

I'm new to javascript and programming in general. I would like to use this: https://github.com/CesiumGS/gltf-pipeline It's a tool to convert models into compressed formats. This is my code:

const gltfPipeline = require("gltf-pipeline");
const fsExtra = require("fs-extra");
const processGltf = gltfPipeline.processGltf;
const gltf = fsExtra.readJsonSync("model.gltf");
const options = {
  dracoOptions: {
    compressionLevel: 10,
  },
  separateTextures: true,
};
processGltf(gltf, options).then(function (results) {
  fsExtra.writeJsonSync("modeldraco.gltf", results.gltf);
  console.log('done');
  const separateResources = results.separateResources;

  for (const relativePath in separateResources) {
    if (separateResources.hasOwnProperty(relativePath)) {
      const resource = separateResources[relativePath];
      fsExtra.writeFileSync(relativePath, resource);
    }
  }
}); 

I copied this file, saved it as compress.js (because it rhymes) and I then ran it with node compress.js - this is how I'd run a python file.

Error is: Cannot find module 'gltf-pipeline' which makes sense. So, I did:

node -r gltf-pipeline compress.js but I get the same error.

So, I moved to HTML/JS, where I made an index.html file and linked with a <script> tag compress.js and the gltf-pipeline index.js file. These are the errors:

index.js:3 Uncaught ReferenceError: module is not defined
    at index.js:3
(anonymous) @ index.js:3
compress.js:3 Uncaught ReferenceError: require is not defined

So how is this done? Either as a webpage or command line would be helpful. This is my folder structure by the way, maybe that's the issue.

basefolder|
          |- gltf-pipeline| library files in here
          |- compress.js
          |- index.html
          |- model.gltf

gltf-pipeline works when used as a command line tool.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

No.

You can't do that with Javascript.

JS is served to the client.

Whilst NodeJS runs on a server.

These are the differences between node and browser JS.

also for the module error try

npm install gltf-pipeline

Look at NPM to install Node Packages Also take a look at the NodeJS Tutorial

about 4 years ago · Juan Pablo Isaza Denunciar
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