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

[colorette v1.4] tty && tty.isatty(1) breaks in vite HMR mode #67

Closed
LeoniePhiline opened this issue Sep 16, 2021 · 4 comments
Closed

Comments

@LeoniePhiline
Copy link

Hi!

In vite HMR mode, require('tty') returns a mock module, which is auto-defined as:

// browser-external:tty
var tty_exports = {};
__export(tty_exports, {
  default: () => tty_default
});
var tty_default;
var init_tty = __esm({
  "browser-external:tty"() {
    init_define_process_env();
    tty_default = new Proxy({}, {
      get() {
        throw new Error('Module "tty" has been externalized for browser compatibility and cannot be accessed in client code.');
      }
    });
  }
});

Therefore, the check tty && tty.isatty(1) (isCompatibleTerminal) fails with "TypeError: tty.isatty is not a function".

I can't help by disabling via process.env.NO_COLOR, because isCompatibleTerminal is eagerly evaluated, no matter if NO_COLOR is set or not.

Could you please consider:

  1. Aborting without further checks if process.env.NO_COLOR is set.
  2. Or lazily evaluating isCompatibleTerminal only after checking for !isDisabled.

Thank you!

@LeoniePhiline LeoniePhiline changed the title tty && tty.isatty(1) breaks in vite HMR mode [colorette v1.4] tty && tty.isatty(1) breaks in vite HMR mode Sep 21, 2021
@jorgebucaran
Copy link
Owner

Thanks. How would I go about reproducing your environment to test this myself?

@LeoniePhiline
Copy link
Author

  • Create a new vite project. In my case vie & typescript (vue-ts preset)
  • Install sanitize-html, import it in a vue component to use in the browser, and sanitize some html (or any string) with it
  • Start vite HMR mode (npm run dev)
  • Open in the Browser

what happens:
Browser pulls es modules. Sanitize-html imports postcss to parse your html string into an AST. Postcss pulls in colorette 1.4. Colorette crashes the app with tty.isatty(1)

@jorgebucaran
Copy link
Owner

Gotcha, thanks! I believe updating to the latest Colorette should fix it.

@jorgebucaran
Copy link
Owner

2.0.6 includes a check to make sure env exists. We might be able to remove this in the future too.

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.

2 participants