Skip to content

Prime Number Checker export failure crashes the test runner #48

Description

@majestic-owl448

Reproduction

  1. Start Build a Prime Number Checker Module.
  2. Create index.js with:
function isPrime(n) {
  if (n < 2) return false;
  if (n < 4) return true;
  if (n % 2 === 0 || n % 3 === 0) return false;
  for (let i = 5; i * i <= n; i += 6) {
    if (n % i === 0 || n % (i + 2) === 0) return false;
  }
  return true;
}

module.exports = isPrime;
  1. Add a valid CommonJS package.json.
  2. Click Run Tests.

Actual behavior

The page reports:

Error 4XX - 5XX
Client has disconnected from local server

The course test worker fails on the export test with DataCloneError. The test imports the CommonJS module as an ES module namespace. With module.exports = isPrime, the namespace does not expose isPrime directly, so the assertion fails. Its error object contains a function and cannot be sent through parentPort.postMessage.

The later two tests then fail because their fallback assigns the module namespace object to isPrime and attempts to call it.

Expected behavior

The runner should remain connected and show an ordinary failed test with an actionable export message.

The intended submission shape passes all six tests:

module.exports = { isPrime };

Verified against

  • back-end-development-and-apis current main
  • @freecodecamp/freecodecamp-os 3.5.4

The earlier Build a Case Converter course teaches the object export form, but this project's text only says to export isPrime using module.exports and calls it a named export. An explicit expected export snippet would avoid directing learners toward the crashing path.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions