-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed
Labels
bugSomething isn't workingSomething isn't workingnode.jsCompatibility with Node.js APIsCompatibility with Node.js APIs
Description
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
yus-ham
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingnode.jsCompatibility with Node.js APIsCompatibility with Node.js APIs