freeCodeCamp / freeCodeCamp/back-end-development-and-apis
Prime Number Checker export failure crashes the test runner
- Dominant language
- JavaScript
- Stars
- 32
- Forks
- 217
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
## Reproduction
1. Start **Build a Prime Number Checker Module**.
2. Create `index.js` with:
```js
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;
```
3. Add a valid CommonJS `package.json`.
4. 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:
```js
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.
Contributor guide
Research direction
Open the Build a Prime Number Checker course text and compare its export instruction with the earlier Build a Case Converter lesson. Make the expected named export shape explicit, then run the course's six tests to confirm the runner stays connected and reports ordinary failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 74/100