-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
UMD broken in older browsers #6011
Comments
Looks like Probably easier for the user in the short term to have a custom build of PlayCanvas that doesn't have that particular bit of code. (or quickly build one for them) |
There is also a polyfill. Its archived at this point, since all browsers support it natively, but should probably work for old ones. |
I've looked at the polyfill already - it requires a browser supporting modules. But here we're considering running on browsers without modules, as we used to. This is also likely related to this: #5963 (not released, but uses import as well). |
By the way, I believe we use dynamic imports in two places currently:
Both of these are optional from the user perspective, and so we probably do not need to remove these use cases, but just need a solution for old browsers to not fail on parsing of this source code. We can probably just write an Then it will be up to the user to not use APIs that actually depend on it. |
twgsl.js looks like it's an UMD format, so it can just be loaded as a non module script. Worth noting that the import also uses |
Thanks for this @RobertUAggo. I've been able to test and replicate. Older versions of Chrome don't ignore the We're not currently polyfilling imports, and arguably shouldn't as it's only WebGPU which wont work anyway. Regardless, it shouldn't raise the SyntaxError. There may be a Babel feature that supports it, but it essentially boils down to mapping to something like Update: This does not work as import does not exist on globalThis. The only solution I can see here is using something like |
I managed to get Food Run game working with Chromium v62 (links for older versions here: https://vikyd.github.io/download-chromium-history-version/#/) Issues that I had to work around:
Edit: This may be a better polyfill for Object.fromEntries: https://gitlab.com/moongoal/js-polyfill-object.fromentries/-/blob/master/index.js?ref_type=heads |
Update:
With the above, the forked Food Run game I have works 👍 https://playcanvas.com/project/1187223/overview/food-run-pre-62 Complete polyfill I used for the project that is loaded before the engine Edit: Only works for v63+
|
No need to polyfill. The engine only uses
For:
We can quickly submit a PR for that. |
Really awesome investigation though - we'll aim to resolve this based on your suggestions on Monday! 🚀 |
Sorry, correction here: I was testing on the wrong version of Chrome (63 not 62) so my stub of The polyfill that LeXXik mentioned (https://github.com/GoogleChromeLabs/dynamic-import-polyfill) gets around this by creating a new global function The forum user will still need to use a custom engine build for the short term for that code removed. |
I retested everything again under Chrome v53 which is what @RobertUAggo needs for the Samsung TVs Turns out I've added that to the polyfill in this fork of Food Run that also has a custom PC engine build without the import statements: https://playcanvas.com/project/1187223/overview/food-run-pre-62 Updated polyfill:
|
* Adds entries and fromEntries Object polyfill. Partially solves #6011 * export entries polyfill * New line at end of file --------- Co-authored-by: Will Eastcott <will@playcanvas.com>
We get:
[Uncaught SyntaxError: Unexpected token “import”](https://forum.playcanvas.com/t/uncaught-syntaxerror-unexpected-token-import-playcanvas-stable-min-js-6/34656)
in this code:forum post: https://forum.playcanvas.com/t/uncaught-syntaxerror-unexpected-token-import-playcanvas-stable-min-js-6/34656/1
The text was updated successfully, but these errors were encountered: