Open beepsoft opened 10 months ago
@Jarred-Sumner Any idea when this might happen? We (+ probably many other devs) can't migrate our tests to bun due to this issue
@Jarred-Sumner Also having this issue, a lot of my components import something from my config file which includes:
const NODE_ENV = import.meta.env.NODE_ENV
resulting in an error when running tests:
TypeError: undefined is not an object (evaluating 'import.meta.env.NODE_ENV')
As a workaround (worked for me at least) you should be able to create a file, say, fix-import-meta-env.js with the content import.meta.constructor.prototype.env = process.env
then run your scripts with bun -r ./fix-import-meta-env.js my-script.ts
.
Not something you'd want to keep in the long term. Would be nice to get it built in!
Runtime support for import.meta.env is merged, thanks to @otgerrogla. Not yet supported at build-time
What is the problem this feature would solve?
Introducing access to
.env
variables viaimport.meta.env
would make bun more compatible with existing tools (eg. Vite) and would help migrating to bun.What is the feature you are proposing to solve the problem?
It would be great to have support for accessing
.env
variables viaimport.meta.env
as in Vite: https://vitejs.dev/guide/env-and-mode.htmlWhat alternatives have you considered?
No response