Skip to content

Incorrect exitCode when process fails due to circular dependency of dynamic import #53551

@saurabhdaware

Description

@saurabhdaware

Version

20.15.0

Platform

Darwin Saurabhs-MacBook-Air.local 23.0.0 Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:34 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8103 arm64

Subsystem

No response

What steps will reproduce the bug?

CodeSandbox Reproduction

// a.js
export const utilityFunction = () => {
  return 'woah nice utility';
}

process.on('exit', (exitCode) => {
  // This prints 0 but the correct code should be 13
  console.log('exitCode', exitCode);
});

try {
  const defaultImpB = (await import('./b.js')).default;
  console.log('try');
  console.log({defaultImpB});
} catch (e) {
  console.log('catch')
} finally {
  console.log('finally');
}

// b.js
import { utilityFunction } from './a.js';

const test = () => {
  return 'test';
}

export default test;
# This prints exit code 0
node a.js

# This prints exit code 13
echo $?

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

exitCode should return 13 code

What do you see instead?

exitCode returns 0

Additional information

There is #44601 issue which talks about early exit. But my main concern was the exitCode being 0 since there is no other way to debug this issue when process exits with success code

Metadata

Metadata

Assignees

No one assigned

    Labels

    loadersIssues and PRs related to ES module loadersprocessIssues and PRs related to the process subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions