bun icon indicating copy to clipboard operation
bun copied to clipboard

Bun seems to have problems with colored output in TTY

Open gnubyte opened this issue 2 years ago • 1 comments

Hi! I was trying to use bunJS for an express web project I'm working on and it looks like there was a problem maybe with how bunJS handles colored text output. Towards the top of the debug you can see it gets stuck on the colored output here. Not very familiar with Zig but let me know if I can be of assistance!

How to replicate

I think it may occur with any sequelize project and debugging from terminal. I was using the builtin VS-Code terminal in my case. Sequelize is an ORM.

Here is my debug output

gnubyte@pop-os:~/Code/2022/SomeCompanyObscurred/backend$ bun src/index.js
153 |  */
154 |  /*** Is stdout a TTY? Colored output is enabled when `true`.*/
155 | function useColors() {
156 |   return 'colors' in exports.inspectOpts ?
157 |           Boolean(exports.inspectOpts.colors) :
158 |           tty.isatty(process.stderr.fd);
                ^
TypeError: undefined is not an object (evaluating 'process.stderr.fd')
      at useColors (/home/gnubyte/Code/2022/SomeCompanyObscurred/backend/node_modules/sequelize/node_modules/debug/src/node.js:158:13)
      at createDebug (/home/gnubyte/Code/2022/SomeCompanyObscurred/backend/node_modules/sequelize/node_modules/debug/src/common.js:117:20)
      at /home/gnubyte/Code/2022/SomeCompanyObscurred/backend/node_modules/sequelize/lib/hooks.js:4:14
      at bun:wrap:1:16360
      at /home/gnubyte/Code/2022/SomeCompanyObscurred/backend/node_modules/sequelize/lib/model.js:34:22
      at bun:wrap:1:16360
      at /home/gnubyte/Code/2022/SomeCompanyObscurred/backend/node_modules/sequelize/lib/sequelize.js:27:22
      at bun:wrap:1:16360
      at /home/gnubyte/Code/2022/SomeCompanyObscurred/backend/node_modules/sequelize/lib/index.js:2:25
      at bun:wrap:1:16360
      at /home/gnubyte/Code/2022/SomeCompanyObscurred/backend/src/models/index.js:5:26
      at bun:wrap:1:16360
      at /home/gnubyte/Code/2022/SomeCompanyObscurred/backend/src/controllers/auth.js:1:36
      at bun:wrap:1:16360
      at /home/gnubyte/Code/2022/SomeCompanyObscurred/backend/src/routes/auth.js:2:28
      at bun:wrap:1:16360
      at /home/gnubyte/Code/2022/SomeCompanyObscurred/backend/src/index.js:9:27
gnubyte@pop-os:~/Code/2022/SomeCompanyObscurred/backend$ 

gnubyte avatar Oct 14 '22 06:10 gnubyte

This bug is due to missing process.stderr.fd, will be fixed next week

Jarred-Sumner avatar Oct 14 '22 22:10 Jarred-Sumner

@Jarred-Sumner was it fixed? I'm still receiving this error trying to run a Koa server:

> bun run src/index.ts

153 |  */
154 | 
155 | function useColors() {
156 |   return 'colors' in exports.inspectOpts ?
157 |           Boolean(exports.inspectOpts.colors) :
158 |           tty.isatty(process.stderr.fd);
                ^
TypeError: undefined is not an object (evaluating 'process.stderr.fd')
      at useColors (/home/dan/dev/drizzle-team/flyio-litefs/node_modules/.pnpm/[email protected]/node_modules/debug/src/node.js:158:13)
      at createDebug (/home/dan/dev/drizzle-team/flyio-litefs/node_modules/.pnpm/[email protected]/node_modules/debug/src/common.js:117:20)
      at /home/dan/dev/drizzle-team/flyio-litefs/node_modules/.pnpm/[email protected]/node_modules/koa/lib/application.js:9:22
      at bun:wrap:1:16360
      at /home/dan/dev/drizzle-team/flyio-litefs/node_modules/.pnpm/[email protected]/node_modules/koa/dist/koa.mjs:1:0
 ELIFECYCLE  Command failed with exit code 1.

> bun upgrade
Congrats! You're already on the latest version of bun (which is v0.2.2)

dankochetov avatar Nov 17 '22 13:11 dankochetov

Please help. Me too having this issue.

JunyaoC avatar Dec 01 '22 06:12 JunyaoC

The npm package initially threw this error and after upgrade to canary build it stopped throwing it. Seems to have been fixed but I cannot tell for certain as the npm package is throwing other errors now.

0x4a61636f62 avatar Dec 06 '22 12:12 0x4a61636f62

@robobun

const Koa = require('koa');
const app = new Koa();

app.use(async ctx => {
  ctx.body = 'Hello World';
});

app.listen(3000);

const response = await fetch("http://localhost:3000");
console.log(response);

Electroid avatar Dec 07 '22 20:12 Electroid

@Electroid here you go!

This error can also happen if dependencies import packages which are not referenced anywhere. Worst case, run `bun install` and opt-out of the node_modules folder until we come up with a better way to handle this error.rt().
This error can also happen if dependencies import packages which are not referenced anywhere. Worst case, run `bun install` and opt-out of the node_modules folder until we come up with a better way to handle this error.
Code
const Koa = require('koa');
const app = new Koa();

app.use(async ctx => {
  ctx.body = 'Hello World';
});

app.listen(3000);

const response = await fetch("http://localhost:3000");
console.log(response);

Ran using the latest build of Bun, an all-in-one JavaScript runtime.

robobun avatar Dec 07 '22 20:12 robobun

Bun v0.3.0 added support for process.stderr and related APIs, which should have resolved the root issue here.

However, it's possible that koa or sequlize may have other errors. If that's the case, please feel free to open another issue.

Electroid avatar Dec 07 '22 20:12 Electroid

@Electroid here you go!

1 | sequlize;
   ^
ReferenceError: Can't find variable: sequlize
      at /tmp/bun-rpWqJA/index.tsx:1:0
Code
sequlize

Ran using the latest build of Bun, an all-in-one JavaScript runtime.

robobun avatar Dec 07 '22 20:12 robobun