node-jq icon indicating copy to clipboard operation
node-jq copied to clipboard

Using bun results in "TypeError: process.stdin.setEncoding is not a function."

Open jhohlfeld opened this issue 1 year ago • 0 comments

Description

I am using bun runtime and came across an issue that might be relevant for node-jq.

When running this example

jq(".", { foo: "bar" }, { input: "json" }).then(console.log);

bun raises a TypeError: process.stdin.setEncoding is not a function..

The error comes from this line: https://github.com/sanack/node-jq/blob/d339ef9c1713eddc78d5a68b0f5891ba040c3d62/src/exec.js#L35

Following the implementation, I found the spawning childProcess here: https://github.com/sanack/node-jq/blob/d339ef9c1713eddc78d5a68b0f5891ba040c3d62/src/exec.js#L13

Now my understanding is that process.stdin in a child process (subprocess.stdin) is a Writeable stream. However, according to nodejs' documentation, the Writable interface only has setDefaultEncoding, not setEncoding.

Weirdly enough, the node runtime does define setEncoding on the Writable implementation in subprocess.stdin. From my perspective, the way bun is treating the implementation, it's more adhering to the documented behaviour.

Maybe I am missing something and you may find it unrelated to node-jq. However, I still wanted to mention and would appreciate you feedback on it.

Repo for reproduction: https://github.com/jhohlfeld/nodejq-issue-681

Error Message & Stack Trace

TypeError: process.stdin.setEncoding is not a function. (In 'process.stdin.setEncoding("utf-8")', 'process.stdin.setEncoding' is undefined)
      at /Users/jakob/nodejq-issue/node_modules/node-jq/lib/exec.js:44:13
      at new Promise (:1:21)
      at exec (/Users/jakob/nodejq-issue/node_modules/node-jq/lib/exec.js:15:12)
      at /Users/jakob/nodejq-issue/node_modules/node-jq/lib/jq.js:17:13
      at new Promise (:1:21)
      at run (/Users/jakob/nodejq-issue/node_modules/node-jq/lib/jq.js:15:12)
      at /Users/jakob/nodejq-issue/index.ts:3:1

Environment

Tell us which operating system you are using, as well as which versions of Node.js, npm/yarn, and node-jq.

Bun 1.1.5 Node 21.6.0 darwin 23.4.0 node-jq version: 4.3.1

jhohlfeld avatar Apr 28 '24 16:04 jhohlfeld