StarlaneStudios / cirql

🔧 A flexible SurrealDB ORM & query builder with Zod powered validation 🏋️‍♂️
https://cirql.starlane.studio/
MIT License
200 stars 6 forks source link

`EventTarget is not defined` error when importing module #2

Closed PGilbertSchmitt closed 1 year ago

PGilbertSchmitt commented 1 year ago

Describe the bug Receiving error Uncaught ReferenceError: EventTarget is not defined when importing or requiring cirql.

Example In my TypeScript project, I've installed cirql, zod, and ws. However, when I attempt to import or require cirql, I get this failure:

> const cirql = require('cirql')
Uncaught ReferenceError: EventTarget is not defined
    at /home/gilbert/dev/ecmastuff/surreal/node_modules/.pnpm/cirql@0.1.6_ws@8.12.0+zod@3.20.2/node_modules/cirql/dist/cirql.umd.cjs:4:22
    at /home/gilbert/dev/ecmastuff/surreal/node_modules/.pnpm/cirql@0.1.6_ws@8.12.0+zod@3.20.2/node_modules/cirql/dist/cirql.umd.cjs:1:681
    at Object.<anonymous> (/home/gilbert/dev/ecmastuff/surreal/node_modules/.pnpm/cirql@0.1.6_ws@8.12.0+zod@3.20.2/node_modules/cirql/dist/cirql.umd.cjs:1:892)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)

The above was run in the node repl. I receive the same error when I run import cirql from 'cirql' in my TypeScript file and execute it using npx ts-node FILE. This also happens when I run import cirql from 'cirql' in the TS repl (via pnpm exec ts-node) after I attempt introspection on the cirql object. I do not have a tsconfig.json file, so this is the default configuration.

Expected behavior I expect to be able to import the module.

Environment:

macjuul commented 1 year ago

This might be a case of an unsupported version of Node. Cirql was developed against the current LTS 18.13.0. Would you be able to attempt running this on a more up-to-date Nodejs installation?

PGilbertSchmitt commented 1 year ago

That's exactly it. Literally one more minute of searching showed me that while EventTarget exists in NodeJS since version 14.5.0, the EventTarget() constructor wasn't introduced until 15.0.0. This is solved.