Conditional module.exports assignment refuses even under if (true)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 22/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, nodejs, typescript
- Ambito
- compilers
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 6.4k
- Fork
- 204
- Merge medio
- 5h 48m
- PR unite (30g)
- 864
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di vercel-labs/scriptc
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 72/100
vercel-labs/scriptc#2910 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Assigning a wide Node object (process.stdout) to a narrow { write } record fails SC2002 (width-copy rules)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
vercel-labs/scriptc#2949 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
vercel-labs/scriptc#2948 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
SC8006 mistakes shadowed parameters for builtin module patchesForse già presa @MathurAditya724 l’ha presa 1 giorno fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
vercel-labs/scriptc#2919 ·
I maintainer di solito rispondono entro 1 giorno
-
Analysis OOM (exit 137 at ~4 GB) on large TypeScript graphsForse già presa @espetro l’ha presa oggi. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 12/100
vercel-labs/scriptc#2916 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di vercel-labs/scriptc
Issue simili
-
reproduced
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
anomalyco/opencode#61640 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
ai-driven-fuzzing bug Minor
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
ai-driven-fuzzing bug claude Minor
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
linagora/twake-calendar-frontend#1944 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Add: Yichang TVApertacheck:passed streams:add
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno