oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.37k stars 2.78k forks source link

module.parent or module.main or module.children properties are always undefined #14975

Open gherciu opened 2 weeks ago

gherciu commented 2 weeks ago

What version of Bun is running?

1.1.34

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

Have 2 files a.ts and b.ts the a imports b And in a I log this console.log(require.cache) Now in the logged info find the B module and you'll see that the parent field is undefined even tho it should not because a imports b Now my vscode says that .parent is deprecated and I should use .main but this also doesn't work On top of that the .children also doesn't work and I can't figure out what are the child imports of some file to remove them from the cache and thus my app doesn't reload the code correctly when I need

What is the expected behavior?

I should be able to see the parent imports of a module or which is the most important the child imports that this module imported so that I can invalidate them if needed

What do you see instead?

udenfined in all these properties

Additional information

No response

gherciu commented 2 weeks ago

Some context: We need this fix to be able to use this package https://www.npmjs.com/package/import-fresh It is downloaded 42 million times a week, and we also need this in our project I think Bun will benefit from fixing it since a lot of people need this In our case we want to extend it a bit to remove also child imports cache, to have a truly dynamic uncached import