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

js: doesn't show any errors from stderr #17627

Closed
1 of 4 tasks
Maxim-Mazurok opened this issue Jun 16, 2023 · 2 comments · Fixed by #17622
Closed
1 of 4 tasks

js: doesn't show any errors from stderr #17627

Maxim-Mazurok opened this issue Jun 16, 2023 · 2 comments · Fixed by #17622

Comments

@Maxim-Mazurok
Copy link

Current Behavior

I run nodejs scripts using @nx/js:node
When there's a TS compilation or runtime error - I don't see it, tasks exits without any error output.
This makes debugging a nightmare.

Expected Behavior

I can see stderr when using @nx/js:node

GitHub Repo

No response

Steps to Reproduce

  1. Add console.log("test".replaceAll(/a/, "b")); to your script
  2. Run it using @nx/js:node

Nx Report

Node   : 20.2.0
   OS     : win32 x64
   npm    : 9.6.6
   Hasher : Native

   nx                 : 16.3.2
   @nx/js             : 16.3.2
   @nx/jest           : 16.3.2
   @nx/linter         : 16.3.2
   @nx/workspace      : 16.3.2
   @nx/devkit         : 16.3.2
   @nx/eslint-plugin  : 16.3.2
   @nx/plugin         : 16.3.2
   @nrwl/tao          : 16.3.2
   @nx/vite           : 16.3.2
   nx-cloud           : 16.0.5
   typescript         : 5.1.3
   ---------------------------------------

Failure Logs

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

This seems related to #17083

Temporary fix is to add console.error(data.toString()); into node_modules\@nx\js\src\executors\node\node.impl.js:

// Run the program
task.promise = new Promise((resolve, reject) => {
    var _a;
    task.childProcess = (0, child_process_1.fork)((0, devkit_1.joinPathFragments)(__dirname, 'node-with-require-overrides'), (_a = options.runtimeArgs) !== null && _a !== void 0 ? _a : [], {
        execArgv: getExecArgv(options),
        stdio: [0, 1, 'pipe', 'ipc'],
        env: Object.assign(Object.assign({}, process.env), { NX_FILE_TO_RUN: fileToRun, NX_MAPPINGS: JSON.stringify(mappings) }),
    });
    task.childProcess.stderr.on('data', (data) => {
        console.error(data.toString());
        // Don't log out error if task is killed and new one has started.
        // This could happen if a new build is triggered while new process is starting, since the operation is not atomic.
        if (options.watch && !task.killed) {
            devkit_1.logger.error(data.toString());
        }
    });
    task.childProcess.once('exit', (code) => {
        if (options.watch && !task.killed) {
            devkit_1.logger.info(`NX Process exited with code ${code}, waiting for changes to restart...`);
        }
        if (!options.watch)
            done();
        resolve();
    });
    next({ success: true });
});
@Maxim-Mazurok
Copy link
Author

@mandarini thanks for addressing this! There was another related issue I forgot to mention - using npm's debug package, it uses process.stderr.write under the hood, and nx run was "swallowing" all stderr. I assume that your fix addressed this, but I thought I'd mention it here just in case.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants