llrt icon indicating copy to clipboard operation
llrt copied to clipboard

tty library missing

Open paul-uz opened this issue 1 year ago • 1 comments

I am trying to use the following package https://www.npmjs.com/package/@opensearch-project/opensearch?activeTab=readme but I'm currently blocked due to the tty library not being supported.

Being able to use this package is of great importance, as AWS do not have a true "client" library for OS (the one in the v3 SDK if for management of OS services, not for running queries).

Other than trying to get the OS package authors to remove the dependency on the packages that need tty, how can I resolve this?

paul-uz avatar Oct 08 '24 08:10 paul-uz

Looks like there are other issues with that package, which i hit after stubbing tty.

I got a similar error to this one https://github.com/awslabs/llrt/issues/608

paul-uz avatar Oct 08 '24 09:10 paul-uz

I have done some research as well. As you have pointed out, there seem to be some issues.

The following modules and functions are not implemented:

  • tty.isatty()
  • util.deprecate()
  • util.formatWithOptions()
  • util.inspect()

And even if you could implement these, you would probably get an error at this line. This is issue #608 itself.

module.exports = require('./common')(exports);

nabetti1720 avatar Oct 11 '24 10:10 nabetti1720

@paul-uz , As LLRT's Node.js package reading becomes browser-first, the required modules are changing. I already no longer need tty and util on my laptop. Currently, the required components are as follows.

node_modules/@opensearch-project/opensearch/lib/Transport.js:

  • os.arch()
  • Buffer.constants.MAX_LENGTH
  • Buffer.constants.MAX_STRING_LENGTH
  • v8.getHeapStatistics().heap_size_limit

There may be more, but first I will share where we are. :)

P.S. If you are using bundler, I recommend you to use platform: “browser” as it has a better chance of working.

nabetti1720 avatar Oct 24 '24 11:10 nabetti1720

@paul-uz , As LLRT's Node.js package reading becomes browser-first, the required modules are changing. I already no longer need tty and util on my laptop. Currently, the required components are as follows.

node_modules/@opensearch-project/opensearch/lib/Transport.js:

  • os.arch()
  • Buffer.constants.MAX_LENGTH
  • Buffer.constants.MAX_STRING_LENGTH
  • v8.getHeapStatistics().heap_size_limit

There may be more, but first I will share where we are. :)

P.S. If you are using bundler, I recommend you to use platform: “browser” as it has a better chance of working.

Sorry, what does this mean exactly?

Also, I thought you had to use browser as the platform for LLRT anyway?

paul-uz avatar Oct 24 '24 11:10 paul-uz

I can't say it will necessarily work with that, but it is worth a try.

For reference, the @aws-sdk bundled inside LLRT is built with platform: “browser”. I believe this is to avoid Node.js-specific implementations included in @aws-sdk and @smithy, and to use the browser-oriented implementation.

The same could be said for general packages. However, if the package is not prepared with a browser-oriented implementation, this approach makes no sense.

nabetti1720 avatar Oct 24 '24 11:10 nabetti1720

There are many libraries that require the isatty function, such as https://github.com/chalk/chalk

import tty from 'node:tty';

const supportsColor = {
	stdout: createSupportsColor({isTTY: tty.isatty(1)}),
	stderr: createSupportsColor({isTTY: tty.isatty(2)}),
};

ahaoboy avatar Nov 13 '24 14:11 ahaoboy

Basic support added in https://github.com/awslabs/llrt/pull/675

richarddavison avatar Nov 24 '24 20:11 richarddavison