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

Node compat: Add import.meta.dirname and import.meta.filename #7778

Closed
risu729 opened this issue Dec 22, 2023 · 1 comment
Closed

Node compat: Add import.meta.dirname and import.meta.filename #7778

risu729 opened this issue Dec 22, 2023 · 1 comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@risu729
Copy link
Contributor

risu729 commented Dec 22, 2023

What version of Bun is running?

1.0.18+36c316a24

What platform is your computer?

Linux 5.15.0-1048-oracle aarch64 aarch64

What steps can reproduce the bug?

// test.mjs
console.log("dir:", import.meta.dir);
console.log("dirname:", import.meta.dirname);
console.log("file:", import.meta.file);
console.log("filename:", import.meta.filename);

What is the expected behavior?

$ node test.mjs
dir: undefined
dirname: /home/ubuntu
file: undefined
filename: /home/ubuntu/test.mjs

What do you see instead?

$ bun run test.mjs
dir: /home/ubuntu
dirname: undefined
file: test.mjs
filename: undefined

Additional information

Since Node.js v21.2.0, import.meta.dirname and import.meta.filename are added. nodejs/node#48740

import.meta.dirname can be added to Bun as an alias for import.meta.dir.

However, while import.meta.filename in Node.js includes the directory but import.meta.file in Bun does not, import.meta.filename would not be just an alias.
import.meta.filename equals ${import.meta.dir}/${import.meta.file}.

I think the behavior might cause some confusion, but I believe that adding these properties would improve compatibility with Node.js.

Node.js docs: https://nodejs.org/api/esm.html#importmeta
Bun docs: https://bun.sh/docs/api/import-meta

@risu729 risu729 added the bug Something isn't working label Dec 22, 2023
knightspore added a commit to knightspore/bun that referenced this issue Dec 22, 2023
@Electroid Electroid added the node.js Compatibility with Node.js APIs label Dec 22, 2023
@Jarred-Sumner
Copy link
Collaborator

Fixed in #8127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants