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

🐛 BUG: Support __dirname #7606

Open
noClaps opened this issue Dec 22, 2024 · 3 comments
Open

🐛 BUG: Support __dirname #7606

noClaps opened this issue Dec 22, 2024 · 3 comments
Labels
bug Something that isn't working

Comments

@noClaps
Copy link

noClaps commented Dec 22, 2024

Describe the solution

I'm pretty sure this is a bug, but I didn't see a bug report issue so I opened a feature request instead.

I'm getting this error:

Uncaught ReferenceError: __dirname is not defined

Minimal reproduction:

// index.ts
import { Hono } from "hono";

const app = new Hono();

console.log(__dirname);

export default app 

and my wrangler.toml:

main = "index.ts"
compatibility_date = "2024-12-22"
compatibility_flags = ["nodejs_compat"]

Expected behavior

__dirname should output the directory that the file is currently in, similar to import.meta.dir.

@noClaps noClaps added the enhancement New feature or request label Dec 22, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Dec 22, 2024
@emily-shen
Copy link
Contributor

emily-shen commented Jan 2, 2025

Hi, as dirname doesn't really make sense for us to implement as Workers are serverless functions without a filesystem. It should be mocked with nodejs_compat though, so if you're using a library that has __dirname somewhere, but you're not actually relying on that actually outputting a directory name, that should still work (not sure if your repro has been simplified just for demo purposes).

@github-project-automation github-project-automation bot moved this from Untriaged to Done in workers-sdk Jan 2, 2025
@noClaps
Copy link
Author

noClaps commented Jan 2, 2025

The demo was simplified, I was actually using a library that uses __dirname, but it wasn't being mocked with nodejs_compat, hence why I opened the issue. My guess is that because the files get bundled into one single JS file before running, __dirname gets included in that, and it refuses to run.

@emily-shen emily-shen reopened this Jan 2, 2025
@github-project-automation github-project-automation bot moved this from Done to Untriaged in workers-sdk Jan 2, 2025
@emily-shen
Copy link
Contributor

Ah I see, that makes more sense 😅

cc @vicb

@emily-shen emily-shen changed the title 🚀 Feature Request: Support __dirname 🐛 BUG: Support __dirname Jan 2, 2025
@emily-shen emily-shen added bug Something that isn't working and removed enhancement New feature or request labels Jan 3, 2025
@emily-shen emily-shen moved this from Untriaged to Backlog in workers-sdk Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants