Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle reliance on 'window' object as optional #201

Open
haywirez opened this issue Nov 7, 2022 · 2 comments
Open

Handle reliance on 'window' object as optional #201

haywirez opened this issue Nov 7, 2022 · 2 comments

Comments

@haywirez
Copy link

haywirez commented Nov 7, 2022

Right now, the package fails validation when trying to use in node apps or service workers where window is not available:

Uncaught ReferenceError: window is not defined
    at index.js:33:72 in node_modules/gltf-validator/gltf_validator.dart.js
    at index.js:15:50 in __require2
    at index.js:20881:17

Would be nice to address this if possible! My use case involves server-side validation.

@lexaknyazev
Copy link
Member

Please provide more information about the execution and/or development environment. The published npm package works correctly in server-side apps when invoked with the example code from here.

@donmccurdy
Copy link
Contributor

donmccurdy commented Nov 16, 2022

@lexaknyazev glTF Validator has been working for me in a Node.js environment (example). However, I'm not able to use it in a Web Worker either, getting the same error mentioned above. Here's a simplified example:

https://stackblitz.com/edit/donmccurdy-gltf-validator-worker?file=src/validator-worker.js

The project can be downloaded from there with the small button in the sidebar.

It appears that glTF Validator (or the Dart/JS build process?) is checking for a global variable (which would indicate a Node.js environment) and then depending on window if that is not found. In a Web Worker the global variable is called self, which works in the browser's main thread as well.

For applications like https://gltf.report/, it would be helpful to run validation in a Web Worker, as this can otherwise stall the main thread for a noticeable amount of time while the user is applying changes to a scene.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants