Conditional module.exports assignment refuses even under if (true)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #3089 by @imMamdouhaboammar — closed without merging
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 22/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript, nodejs, typescript
- Domain
- compilers
Research direction
Start with the repro: a dep.cjs file containing if (true) { module.exports = ... } is built with packages/cli/dist/main.js build ... --node-islands off, and the native binary exits with SC1090. Read the refusal introduced by #1434 and its test fixture to see which export shapes it rejects. Done means the constant-true case returns the same function and output as Node, and the fixture still refuses the non-constant case.
Written by the indexing model from the issue text.
Description
A module.exports assignment inside a branch is refused at module initialization even when the condition is the literal true. The build succeeds; the executable exits with SC1090 before the importer can use the exported function.
Reproduced on Linux x86_64 with scriptc 0.4.7, compiler source 71450b617d848ee79417762c826f545002468f16 from #2842 on base 5989ca7edec19af60379f41e97904b849955c0fb, and Node v24.22.0. The #2842 change concerns a util function value and does not change this export guard.
From a built scriptc checkout, with Node v24.22.0 selected:
task_cjs_repro=$(mktemp -d)
cat > "$task_cjs_repro/dep.cjs" <<'JS'
if (true) { module.exports = function sleep() { return 'shared' } }
JS
cat > "$task_cjs_repro/main.cjs" <<'JS'
const sleep = require('./dep.cjs')
console.log(typeof sleep, sleep())
JS
node "$task_cjs_repro/main.cjs"
node packages/cli/dist/main.js build "$task_cjs_repro/main.cjs" --node-islands off -o "$task_cjs_repro/native"
"$task_cjs_repro/native"
printf 'native_exit=%s\n' "$?"
Node prints:
function shared
The native build succeeds and prints its artifact path. Running that artifact prints no stdout, reports the following error, and exits 1. The temporary-directory prefix is shortened here:
Uncaught Error: replacing module.exports outside a top-level statement (a conditional or environment-dependent export object) is not supported yet [SC1090 at <repro>/dep.cjs:1]
The expected behavior for this constant-condition case is the same exported function and output as Node. This reproduction uses no npm dependency, SharedArrayBuffer, Atomics, timers, or network activity.
The broader real-world shape comes from Pino's atomic-sleep dependency:
if (typeof SharedArrayBuffer !== 'undefined' && typeof Atomics !== 'undefined') {
module.exports = function sleep () { return 'shared' }
} else {
module.exports = function sleep () { return 'fallback' }
}
Both the runtime-capability version and the constant-true version reach the named export-placement refusal. The constant version isolates the problem from support for those builtins. A control with a single top-level conditional-expression export compiles and selects the expected function; no compiler fix is proposed here.
Related work:
- #1434 intentionally introduced the named conditional-export refusal and its test fixture.
- #1558 was closed unmerged under the upstream CommonJS scope decision. This report records the smaller constant-branch case rather than proposing broader export-object emulation.
- #2295 is an open proposal for
process.envdefines; it does not directly address this literal-true reproduction or builtin capability checks. - Open #1777 tracks other CommonJS entry/resolution failures, including SC2013. It does not contain this SC1090 reproduction.
I checked the open issue list and searched for module.exports, CommonJS, conditional exports, and atomic-sleep before filing; no equivalent open issue was found. This is an issue and reproduction only, with no implementation PR.
- Dominant language
- TypeScript
- Stars
- 6.7k
- Forks
- 229
- Avg merge
- 14h 29m
- Merged PRs (30d)
- 787
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vercel-labs/scriptc
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
vercel-labs/scriptc#4865 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
vercel-labs/scriptc#4864 ·
Maintainers usually reply within 1 day
-
Windows ARM64 as a cross-compile targetPossibly taken @hum-n claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
vercel-labs/scriptc#4858 ·
Maintainers usually reply within 1 day
-
post-merge-bisect-unresolved
Difficulty 3/5 1-2 days Newbie friendliness 43/100
vercel-labs/scriptc#4791 ·
Maintainers usually reply within 1 day
-
post-merge-bisect-unconfirmed
Difficulty 5/5 Over a week Newbie friendliness 12/100
vercel-labs/scriptc#4755 · 1 comment ·
Maintainers usually reply within 1 day
All issues in vercel-labs/scriptc
Similar issues
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1293 ·
Maintainers usually reply within 1 day
-
area: middleware enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
agent/quality testing
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
juspay/agent-distro#203 ·
Maintainers usually reply within 1 day