Closed
Description
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:
execjs/lib/execjs/external_runtime.rb
Line 210 in 6c1c228
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>'
Metadata
Metadata
Assignees
Labels
No labels