denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.06k stars 5.14k forks source link

std/node/_events.mjs assumes existence of process, crashes on calling process.emitWarning #23709

Open tkafka opened 1 week ago

tkafka commented 1 week ago

Version: Deno 1.43.1

I have a Deno program using mysql2 database pool, and running it crashes on

error: Uncaught TypeError: Cannot read properties of undefined (reading 'emitWarning')
            connection.on('error', function (err) {
                       ^
    at _addListener (ext:deno_node/_events.mjs:471:15)
    at PoolConnection.addListener (ext:deno_node/_events.mjs:485:10)

Here is the file and a call site - it calls process.emitWarning without requiring process anywhere: https://github.com/denoland/deno/blob/main/ext/node/polyfills/_events.mjs#L471

I had to do this in my code to prevent the crash:

// let's add process to global variables, so that _events.mjs is happy being able to call process without declaring it
import process from 'node:process'
window.process = process

I run my deno script with deno run --allow-read --allow-write --allow-net --allow-env ./db-maintenance.ts

(I am not a Deno expert, just a node.js developer trying Deno for scripting some database maintenance)