Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nathanbedford opened this issue Oct 23, 2024 · 6 comments
Open

Comments

@nathanbedford
Copy link

nathanbedford commented Oct 23, 2024

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

  • Added Node 23 distinction (Heroku just upgraded to use Node 23 while Digital Ocean is still using 22)
  • Added source code example
@nathanbedford
Copy link
Author

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
Copy link
Author

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

@isaacs
Copy link
Owner

isaacs commented Oct 23, 2024

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
Copy link
Author

nathanbedford commented Oct 24, 2024

@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!

@nathanbedford nathanbedford changed the title "../" being added to files when rootPath has trailing slash on Heroku "../" being added to files when cwd has trailing slash on Node 23 Oct 24, 2024
@adnanel
Copy link

adnanel commented Oct 31, 2024

To me this seems like a bug in node rather than in glob, I reported it there for now - nodejs/node#55612

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

@nathanbedford
Copy link
Author

Awesome, thanks @adnanel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants