nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.57k stars 29.58k forks source link

Buffer() deprecation check throws TypeError: Cannot read properties of null (reading '0') inside new Promise() #54296

Open hyrious opened 2 months ago

hyrious commented 2 months ago

Version

First seen in v20.15; No issue in v20.14

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

No response

What steps will reproduce the bug?

Just create a file and run:

new Promise(() => {
  new Buffer(0)
})

How often does it reproduce? Is there a required condition?

It requires Node.js ≥ v20.15. Node.js v20.14 is working fine.

What is the expected behavior? Why is that the expected behavior?

It should not throw.

What do you see instead?

node:internal/util:508
        filename[0] !== '/' &&
                ^

TypeError: Cannot read properties of null (reading '0')
    at isInsideNodeModules (node:internal/util:508:17)
    at showFlaggedDeprecation (node:buffer:178:8)
    at new Buffer (node:buffer:266:3)
    at file:///Users/hyrious/test.js:5:3
    at new Promise (<anonymous>)
    at file:///Users/hyrious/test.js:4:1
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)

Additional information

The error occurs only when inside the callback of new Promise(). I looked at devtools and it says one item inside the stack has getFileName()null.

jakecastelli commented 2 months ago

Thanks for the report, this has been fixed on the v22.5 in this PR but has not been backported into v20.x release line, it possibly will be fixed in the next release in v20.x.

RedYetiDev commented 2 months ago

I've added LTS watch labels to the PR for backporting, feel free to undone.