Skip to content

NodeJS Error/Fix process.stdout.clearLine not found #67

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

Open
Cupidazul opened this issue Aug 3, 2022 · 1 comment
Open

NodeJS Error/Fix process.stdout.clearLine not found #67

Cupidazul opened this issue Aug 3, 2022 · 1 comment

Comments

@Cupidazul
Copy link

Cupidazul commented Aug 3, 2022

Error occurs in node 14.x. process.stdout.clearLine and cursorTo not found ...

Fix: ProgressBar.js

class LoadingBar {
    constructor() {
        this.interval = 100;
        this.currentIndex = 0;
        this.fill = '█';
        this.empty = '⣿';
        this.bar_length = 50;
        this.loop = null;
        this.flip = 1;
        this.chunksDownloaded = "0";
        this.isRunning = false;
        this.success = ' √';
        this.failed = ' X';
        this.message = '';
        this.messageSize = 0;
    }
    reset() {
        this.constructor();
    }
    next() {
        this.clear();
        this.currentIndex += this.flip;
        if (this.currentIndex === this.bar_length || this.currentIndex === 0) {
            this.flip *= -1;
        }
        let _left = this.currentIndex - 1;
        _left = _left < 0 ? 0 : _left;
        let _right = this.bar_length - _left - 1;
        const _str = `${this.message}${this.chunksDownloaded} :` + chalk.green(` ${this.empty.repeat(_left)}${this.fill}${this.empty.repeat(_right)}`);
        this.messageSize = _str.length;
        process.stdout.write(_str);
    }
    clear() {
        if ('undefined'!=typeof(process.stdout.clearLine)) {
            //@ts-ignore
            process.stdout.clearLine();
            //@ts-ignore
            process.stdout.cursorTo(0);
        } else {
            if (this.currentIndex>0) process.stdout.write('\b'.repeat(this.messageSize));
        }
    }

.
.
.
.
@Cupidazul Cupidazul changed the title NodeJS Error process.stdout.clearLine not found NodeJS Error/Fix process.stdout.clearLine not found Aug 3, 2022
@AlexStormwood
Copy link

This is still an issue, and has been an issue for quite some time.

Also referenced in the main AndroidJS repo: android-js/androidjs#161

And the error I got from attempting to just build a plain, freshly-generated AndroidJS project in GitHub Actions:

Run npm run build:prod

> {my project name was here}@0.0.1 build:prod
> androidjs build --release

--release= true
Downloading: https://github.com/android-js/androidjs-sdk/archive/master.zip
/opt/hostedtoolcache/node/20.11.0/x6[4](https://github.com/{my org name was here}/{my repo name was here}/actions/runs/{GA Run ID was here}/job/{GA Job ID was here}#step:7:5)/lib/node_modules/androidjs-builder/modules/Html/ProgressBar.js:36
        process.stdout.clearLine();
                       ^

TypeError: process.stdout.clearLine is not a function
    at LoadingBar.clear (/opt/hostedtoolcache/node/20.11.0/x64/lib/node_modules/androidjs-builder/modules/Html/ProgressBar.js:36:24)
    at LoadingBar.next (/opt/hostedtoolcache/node/20.11.0/x64/lib/node_modules/androidjs-builder/modules/Html/ProgressBar.js:24:14)
    at Timeout._onTimeout (/opt/hostedtoolcache/node/20.11.0/x64/lib/node_modules/androidjs-builder/modules/Html/ProgressBar.js:43:18)
    at listOnTimeout (node:internal/timers:[5](https://github.com/{my org name was here}/{my repo name was here}/actions/runs/{GA Run ID was here}/job/{GA Job ID was here}#step:7:6)[7](https://github.com/{my org name was here}/{my repo name was here}/actions/runs/{GA Run ID was here}/job/{GA Job ID was here}#step:7:8)3:17)
    at process.processTimers (node:internal/timers:514:7)

Node.js v20.[11](https://github.com/{my org name was here}/{my repo name was here}/actions/runs/{GA Run ID was here}/job/{GA Job ID was here}#step:7:12).0
Error: Process completed with exit code 1.

Really does look like it's only that clear() function in the code shown in the snippet posted for this issue that is causing the problem.

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

No branches or pull requests

2 participants