msub2 / aframe-exokit-avatars

A wrapper for the Exokit Avatars system in an A-Frame component.
https://msub2.github.io/aframe-exokit-avatars/examples/
MIT License
19 stars 6 forks source link

ReferenceError: window is not defined #1

Closed chrismatthieu closed 2 years ago

chrismatthieu commented 2 years ago

After cloning project and running npm install, I received:

topher@matrix aframe-exokit-avatars % node index.js node:internal/errors:464 ErrorCaptureStackTrace(err); ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '/Users/topher/Projects/aframe-exokit-avatars/node_modules/exokit-avatars/' imported from /Users/topher/Projects/aframe-exokit-avatars/index.js at new NodeError (node:internal/errors:371:5) at legacyMainResolve (node:internal/modules/esm/resolve:335:9) at packageResolve (node:internal/modules/esm/resolve:877:14) at moduleResolve (node:internal/modules/esm/resolve:929:18) at defaultResolve (node:internal/modules/esm/resolve:1044:11) at ESMLoader.resolve (node:internal/modules/esm/loader:422:30) at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40) at ModuleWrap. (node:internal/modules/esm/module_job:76:40) at link (node:internal/modules/esm/module_job:75:36) { code: 'ERR_MODULE_NOT_FOUND' }

So I ran npm install exokit-avatars followed by an npm run build which cleared the above error but now I'm getting the following window error:

node index.js file:///Users/topher/Projects/aframe-exokit-avatars/node_modules/exokit-avatars/dist/avatars.module.js:1868 window.Avatar = Avatar; ^

ReferenceError: window is not defined at file:///Users/topher/Projects/aframe-exokit-avatars/node_modules/exokit-avatars/dist/avatars.module.js:1868:1 at ModuleJob.run (node:internal/modules/esm/module_job:185:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:281:24) at async loadESM (node:internal/process/esm_loader:88:5) at async handleMainPromise (node:internal/modules/run_main:65:12)

Any help would be greatly appreciated! Thanks!

msub2 commented 2 years ago

It looks like you're trying to run index.js inside Node, which isn't how this is meant to be used. It's designed so that you simply include the built aframe-exokit-avatars.min.js file inside a script tag along with your A-Frame scene (or in a larger bundle file if necessary), similar to other A-Frame components. You can peek in the examples folder for what a minimal but functional scene looks like using it.

chrismatthieu commented 2 years ago

Thanks for your quick response! I can run your example without errors on my Mac but don't see anything but a ground plane. Is this perhaps intended to be run in VR (Oculus)?

Screen Shot 2022-07-02 at 8 59 05 PM

chrismatthieu commented 2 years ago

Update. I can see my hands and a little bit of my own face if I move backwards fast. I guess that means it's working in 1st person. I tried loading the same page in a new tab but didn't see the other avatar. Perhaps I need to add multiplayer or maybe a mirror into the room to see myself.

I am seeing a bunch of errors on the webserver side that looks like this:

2022-07-02_21:04:25 webserver: module present but fails to load: /Users/topher/Projects/aframe-exokit-avatars 2022-07-02_21:04:25 webserver: Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/topher/Projects/aframe-exokit-avatars/dist/aframe-exokit-avatars.min.js from /usr/local/lib/node_modules/webserver/webserver not supported. aframe-exokit-avatars.min.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename aframe-exokit-avatars.min.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/topher/Projects/aframe-exokit-avatars/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

at globalThis.mod_load (/usr/local/lib/node_modules/webserver/webserver:145:10)
at dispatch (/usr/local/lib/node_modules/webserver/webserver:125:13)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/webserver/webserver:94:4)
at IncomingMessage.emit (node:events:402:35)
chrismatthieu commented 2 years ago

BTW, I started a new project and included your aframe-exokit-avatars.min.js and example and there were no errors on the server side. Thanks!