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.

Loaders - ObjectLoaders and other example loaders giving TypeError in react-native

See original GitHub issue

[TypeError: undefined is not an object (evaluating ‘response.body.getReader’)]

Above error is produced when load function of any loader ( like GLTFLoader or ObjectLoader ) is called.

Platforms tested on:

Mobile - iPhone OS: iOS, MacOS Three.js version 0.135.0 expo-three version 6.0.1 expo-gl version 11.0.3 expo version 43.0.2 react version 17.0.1 react-native version 0.64.3

Sample Code:

const asset = Asset.fromModule(
    require("./assets/v_knife_karam/v_knife_karam.gltf")
  );
  await asset.downloadAsync();

  const loader = new GLTFLoader();

  loader.load(
    asset.uri,
    (gltf) => {
      // model = gltf.scene;
      scene.add(gltf.scene);
    },
    (xhr) => {
      console.log(`${(xhr.loaded / xhr.total) * 100}% loaded`);
    },
    (error) => {
      console.error("An error happened", error);
    }
  );

Error : [TypeError: undefined is not an object (evaluating ‘response.body.getReader’)]

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
gkjohnsoncommented, Dec 15, 2021

I thought this was an unnecessary breaking change that was only causing problems for native and older platforms

I think it’s more accurate to say that three.js made a change that exposed a bug in react-native / the polyfill. In terms of the benefits of the change the fetch implementation simplified the handling of data URIs in the FileLoader, is easier to follow, and personally I’d like to see Loaders take a set of fetch options in the future considering how much more ergonomic they are.

As for issues, response.arrayBuffer would rely on github/fetch#992, but it looks like native’s networking stack would need some work for full compliance.

Have you created an issue for react-native, then? Again this is clearly a shortcoming of these other packages and limits the broader js ecosystems ability to leverage stable, modern APIs. Asking libraries to stall modernization to support workarounds for issues in other packages with no plan or effort to alleviate it is hard to support.

I was hoping this wouldn’t be a hassle, but if it is, then I think this is something that can live in three-stdlib. They already target node, so it should be fine to move FileLoader there.

What I’m really asking for is for some effort to be made to fix the fetch polyfill and react native here instead of expecting three.js to revert because it’s the easy way out. I think instead this effort is best spent making a PR for github fetch to fix the res.arrayBuffer issue and informing or making a PR for react-native to improve the fetch behavior if that’s needed there too. Seeing what kind of progress can or can’t be made on either project I’d think would better inform decision made by three.js.

And to be clear – like I’ve said before – this ultimately isn’t up to me but these are my opinions.

2reactions
Mugen87commented, Dec 16, 2021

If Node isn’t a platform that three supports

three.js does not officially support node environments. As mentioned in the documentation (section Node.js), the engine is designed for the web and relies on Web APIs which are not necessarily supported in node.js.

That said, we try make a node integration easier with PRs like #10732 or #14914 but only if the changes do not affect the code base too much.

In this particular case, the issue needs to be solved elsewhere like mentioned in https://github.com/mrdoob/three.js/issues/23015#issuecomment-994251807.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native Three js expo-three : Example Model Loaders ...
React Native Three js expo-three : Example Model Loaders giving [TypeError: undefined is not an object (evaluating 'response.body.
Read more >
You May need additional loader to handle the result of these ...
Here's my workaround for this one (create-react-app, latest react-leaflet). Hopefully useful for someone stumbling on the issue as well. The ...
Read more >
React Native Expo threejs Loaders error while loading 3D ...
React Native Expo threejs Loaders error while loading 3D models ... but all giving the same " TypeError: undefined is not an object...
Read more >
Loaders - webpack
Loaders are transformations that are applied to the source code of a module. They allow you to pre-process files as you import or...
Read more >
ActivityIndicator - React Native
Displays a circular loading indicator. Example​. Function Component; Class Component. ActivityIndicator Function Component Example.
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