isaacs / node-glob

glob functionality for node.js
ISC License
8.52k stars 480 forks source link

"../" being added to files when cwd has trailing slash on Node 23 #611

Open nathanbedford opened 1 month ago

nathanbedford commented 1 month ago

Hi folks!

Just last night we started noticing an issue with glob on Heroku, where the 'files' array returned from glob has leading "../" characters, but only on Heroku (using Node 23) and only when the cwd has a trailing slash.

When using this:

glob("**/**", {
    cwd: "./static/",
    absolute: false,
    follow: true,
    nodir: true,
    dot: true,
  }

The output looks like this:

Example output

[
    "..",
    "../two.txt",
    "../one.txt"
],

It should look like this:

[
    ".",
    "two.txt",
    "one.txt"
  ]

Reproduction info

You can see the code I used here to reproduce this: https://github.com/avodah-dev/glob-slash-weirdness/blob/main/index.js

Here's how it looks when deployed to Heroku, with the trailing slash on rootPath: https://glob-test-aace9e4820c6.herokuapp.com/?s=1

And using the "s" query param here's how it looks without the trailing slash: https://glob-test-aace9e4820c6.herokuapp.com/?s=0

Digital Ocean example (working correctly)

For reference, it works correctly when I run it locally or on Digital Ocean (app platform) using Node 22: https://sea-turtle-app-vg7i8.ondigitalocean.app/?s=1

Background

We stumbled into this issue last week on Heroku, initially using a 3rd-party buildpack for pnpm, but then confirmed to be an issue using the official NodeJS buildpack, and using npm today.

It was working great yesterday morning on Heroku, but then started breaking on new builds last night (10/22/2024).

I'll create a support ticket with Heroku in case it's an issue completely on their end, but I was hoping glob maintainers might know what's going on too.

Updated

nathanbedford commented 1 month ago

Some extra info I just though of that might be helpful to track this down:

On Heroku, the exact same code from my project that ran correctly two days ago is breaking now. If I use Heroku's "rollback" feature, the old deployment package works correctly now, but when I use that same code and deploy again it break. My guess is that something in Heroku's infrastructure (libraries, packages, etc) changed and is conflicting now with something in glob.

nathanbedford commented 1 month ago

Here's the ticket with Heroku too: https://help.heroku.com/sharing/e9c0e6d9-22b0-4109-88ad-c350b6527ec2

isaacs commented 1 month ago

Can you provide an example that's just using glob, not a web app running on heroku or digital ocean? I'm not really sure how to know what the issue is. Just a standalone node program with expectations and actual values would be great.

nathanbedford commented 1 month ago

@isaacs I was just now about to narrow it down to an issue with Node 23.0.0. I can reproduce it locally and with any environment using v23 - it only showed up on Heroku because they must have rolled out support for that version recently for node projects with a 'node' engine requirement of 22 or greater (see below) while Digital Ocean is still using v22 for the same configuration.

"engines": {
    "node": ">=22.x.x"
  }

Here's a more minimal repro: https://github.com/avodah-dev/glob-node23-issue/blob/main/worker.js

The fix for me, for now, is to update my projects to stick with Node 22 or below, but hopefully this will help folks prep glob for the future versions of Node.

Thanks for your quick attention to this - your question forced me to dig a bit deeper and find the root issue. I appreciate all that you do for the Node community!

adnanel commented 1 month ago

To me this seems like a bug in node rather than in glob, I reported it there for now - https://github.com/nodejs/node/issues/55612

This was a bug in node, it's been fixed in 23.1.0. Originally reported here

nathanbedford commented 1 month ago

Awesome, thanks @adnanel.