module p.js
import url from 'url';
export function _file(){
return url.fileURLToPath(import.meta.url)
}
index.js
import {_file} from './p.js';
console.log(_file()); // returns p.js instead of index.js
i want the index.js file address to be returned.
i know can pass the import.meta.url in the index.js as a method parameter, but I want to know if there is another way or not ???
There is not.
The module knows its own filename.
It doesn't know the name of some file some arbitrary distance up the stack.