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

Bun runtime fails if there's an .env file in the working directory #130

Closed
Burgestrand opened this issue Sep 15, 2023 · 2 comments · Fixed by #131
Closed

Bun runtime fails if there's an .env file in the working directory #130

Burgestrand opened this issue Sep 15, 2023 · 2 comments · Fixed by #131

Comments

@Burgestrand
Copy link

Burgestrand commented Sep 15, 2023

Hi!

When there's an .env in the working directory of Bun, the Bun runtime crashes with a JSON parse error.

I believe the reason for the crash is because Bun outputs [0.32ms] ".env" to STDERR when it loads the .env-file, and the bun runner (or external runtime?) combines STDERR with STDOUT into a single output value, which is then parsed with JSON.parse.

It seems the external runtime merges STDERR on purpose:

io = IO.popen(binary.split(' ') << filename, **(@popen_options.merge({err: [:child, :out]})))

Reproduction steps

This is reproducible on master.

require "bundler/setup"
require "execjs"

ExecJS.runtime = ExecJS::Runtimes::Bun

Dir.mktmpdir do |dir|
  Dir.chdir(dir)

  # Works fine.
  $stdout.puts ExecJS.eval("1+1")

  # Crashes with JSON parse error.
  File.write(".env", "FOO=BAR")
  $stdout.puts ExecJS.eval("1+1")
end

Result:

2
/Users/kim/.asdf/installs/ruby/3.1.2/lib/ruby/3.1.0/json/common.rb:216:in `parse': 451: unexpected token at 'ms] ".env" (JSON::ParserError)
["ok"]'
        from /Users/kim/.asdf/installs/ruby/3.1.2/lib/ruby/3.1.0/json/common.rb:216:in `parse'
        from /Users/kim/Projects/execjs/lib/execjs/external_runtime.rb:69:in `extract_result'
        from /Users/kim/Projects/execjs/lib/execjs/external_runtime.rb:40:in `exec'
        from /Users/kim/Projects/execjs/lib/execjs/external_runtime.rb:15:in `initialize'
        from /Users/kim/Projects/execjs/lib/execjs/runtime.rb:68:in `new'
        from /Users/kim/Projects/execjs/lib/execjs/runtime.rb:68:in `compile'
        from /Users/kim/Projects/execjs/lib/execjs/runtime.rb:55:in `eval'
        from /Users/kim/Projects/execjs/lib/execjs/module.rb:23:in `eval'
        from example.rb:14:in `block in <main>'
        from /Users/kim/.asdf/installs/ruby/3.1.2/lib/ruby/3.1.0/tmpdir.rb:96:in `mktmpdir'
        from example.rb:6:in `<main>'
@casperisfine
Copy link

FYI: @terracatta

@byroot
Copy link
Member

byroot commented Sep 16, 2023

Fixed in 2.9.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants