TypeError: Cannot read property 'forEach' of undefined
See original GitHub issueHello there. General Kenobi.
I created a PNG Thumbnails Batch Renderer with your awesome project and sometimes it stops just because source model file has something like ‘problems with materials’ i think… BUT. I can see the model… Idk how to organize try catch with model-viewer just with vanilla js… sorry))
Can you handle this case without type error please?
model-viewer.js:56233 Uncaught (in promise) TypeError: Cannot read property 'forEach' of undefined
at new Sm (model-viewer.js:56233)
at HTMLElement.[onModelLoad] (model-viewer.js:56342)
at vc.<anonymous> (model-viewer.js:48752)
at vc.dispatchEvent (model-viewer.js:1689)
at vc.setupScene (model-viewer.js:44589)
at vc.setSource (model-viewer.js:44577)
at async HTMLElement.[updateSource] (model-viewer.js:49041)
at async HTMLElement.[updateSource] (model-viewer.js:53334)
Screens:
From:
class Model {
constructor(correlatedSceneGraph, onUpdate = () => { }) {
this[_a] = [];
const { gltf, gltfElementMap } = correlatedSceneGraph;
gltf.materials.forEach(material => {
this[$materials].push(new Material(onUpdate, gltf, material, gltfElementMap.get(material)));
});
}
source glb (14mb) (not mine) https://cloudflare-ipfs.com/ipfs/QmeqKjz7KLigLis1AJGbuu22uXdgGdNaVneFF1MiDkoaPJ
from object 6137 at hic et nunc gallery.
I’ve checked source file and don’t see any “materials” property.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Cannot read property 'forEach' of undefined - Stack Overflow
And undefined has no forEach method. To fix this, always make sure you put a semicolon at the end of your lines (or...
Read more >TypeError: Cannot read property 'forEach' of Undefined in JS
The "Cannot read property 'forEach' of undefined" error occurs when the forEach() method is called on an undefined value. To solve the error,...
Read more >[AskJS] Why does this simple forEach give error Cannot read ...
But the following code gives an error script.js?v=3:196 Uncaught TypeError: Cannot read property 'forEach' of undefined :
Read more >typeerror: cannot read properties of undefined (reading 'foreach')
Your problem is that you are trying to loop though the data object which is not a array. You can only use the...
Read more >Error: Cannot read property 'forEach' of undefined #249 - GitHub
js from the contentful-management package] . Therefore this error message doesn't have the expected pattern and isn't a JSON string. Instead the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Since
toBlob()
returns a promise, I believe you can catch errors this way: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catchThis looks like a regression; we have code specifically to handle this case where the glTF only has the default material.