xeokit-convert icon indicating copy to clipboard operation
xeokit-convert copied to clipboard

Error: ReferenceError: Response is not defined - when running convert2xkt from code

Open elyrank opened this issue 3 years ago • 4 comments

using latest version - 1.1.0

I'm trying to run:

convert2xkt({
        WebIFC,
        source: options.source,
        format: options.format,
        metaModelSource: options.metamodel,
        output: options.output,
        includeTypes: options.include ? options.include.slice(",") : null,
        excludeTypes: options.exclude ? options.exclude.slice(",") : null,
        rotateX: options.rotatex,
        reuseGeometries: (options.disablegeoreuse !== true),
        minTileSize: options.mintilesize,
        includeTextures: options.textures,
        includeNormals: options.normals,
        outputXKTModel: (xktModel) => doSomethingElse(xktModel, options.output),
        log
    }).then(() => {
        log(`[convert2xkt] Done.`);
        process.exit(0);
    }).catch((err) => {
        console.error(`Error: ${err}`);
        process.exit(1);
    });

in order to be able to read the xktModel. but I just keep getting this error: Error: ReferenceError: Response is not defined.

looks like it fails on this function:

function validHTTPResponse(data) {
  if (data instanceof Response) {
    if (data.status === 204) {
      return false;
    }
  }

  return true;
}

I also tried to remove the line I added with the outputXKTModel, but still it doesn't work. only when I run the script directly from cmd it works, but then I cannot access the xktModel Data

elyrank avatar Aug 18 '22 17:08 elyrank

Might take a day or two to patch this one, so if anyone feels adventurous... ;)

xeolabs avatar Aug 18 '22 17:08 xeolabs

A hack could be to create a mock object at initialization to make this useless test not crash.

# Create a mock Response object to fix a Nodejs dependency in loader.gl 
window.Response = class Response {};

Amoki avatar Aug 19 '22 11:08 Amoki

Hmm weird that you're getting such an error, since (if I understand this issue correctly) convert2xkt.js seems to run OK and basically doing what you're doing, with extra options etc. You should be able to just copy that script as a starting point and modify to your needs...

xeolabs avatar Aug 19 '22 12:08 xeolabs

yes, it is weird , that's exactly what I did and it is still not working, no idea why

elyrank avatar Aug 21 '22 07:08 elyrank