Hi Sam, thanks for checking this, this might be more of any issue with my Vite configuration but I wanted to respond with my train of thought to see if it helps clarify my question:
From my understanding, Vite will bundle and minify the React components in a React app into the file "index-Bw7omusj.js" (or whatever naming is chosen).
I guess I'm confused between running my app in the client browser (where DOM is available), and where/why/how Vite is running the production server with no DOM (unless Server-Side Rendering is available, which I'm not using).
I'm thinking Vite grabs the generated "maze_builder.js" when it's imported in a React component -- and maybe Vite is not verifying or stripping out the DOM when it bundles and generates "index-Bw7omusj.js". I opened the minified file "index-Bw7omusj.js" and looked for certain lines of code shown in Chrome dev tools that threw errors:
for(const l of document.querySelectorAll('link[rel="modulepreload"]'))r(l);
This line threw an error in Chrome Dev Tools with "Uncaught ReferenceError: document is not defined at index-Bw7omusj.js:1:364 " and along those lines. I kind of got my hands dirty and tried editing the minified file to include "if (typeof window !== 'undefined')" but that didn't feel like the right approach.
"If vite is defining things like `window`, even under node, do you know why it is doing that - "Why do you think this is an emscripten issue?"
From the research that I've done thus far, the DOM is not present in Node or server environments so that condition should fail. I thought there might be an Emscripten configuration I missed... ? I think this might be a Vite-related bundling issue.
I wanted to make sure I was using the Emscripten compiler switches correctly too. ("-s ENVIRONMENT=web,node, etc.."). I did a build with "-s ENVIRONMENT=node" only, but that didn't really solve the issue because then I can't run the app in the client browser locally or in Vite's production preview.