.ts files run as ES modules under tsconfig module: node16/node18/nodenext, ignoring package.json "type"
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- node.js, typescript
- Ambito
- backend
Direzione di ricerca
Start with default_module_from_tsconfig in src/lib.rs and trace how node16, node18, and nodenext determine the module format for .ts and .tsx files. Reproduce with the provided require example under --import @oxc-node/core/register, then check the behavior for imported CommonJS files and test files run with --test. Done means these settings respect the package "type" and the reproduction behaves as expected; pull request #908 is already open.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
While investigating #905, the LLM stated it found a bug;
Versions: oxc-project/oxc-node main (ffa98c1), @oxc-node/core 1.0.1, Node.js v26.12.1, linux-x64
Repro
package.json (or no "type")
{ "type": "commonjs" }
tsconfig.json (same with node16 or node18)
{ "compilerOptions": { "module": "nodenext" } }
entry.ts
const os = require("node:os");
console.log("ok", typeof os.platform);
node --import @oxc-node/core/register ./entry.ts
Expected: ok function. Under node16, node18 and nodenext, tsc emits each .ts file in the format its package.json "type" gives it, and a package without "type" is CommonJS. So tsc compiles this file to CommonJS. Node's own type stripping (node ./entry.ts) prints the same.
Actual: ReferenceError: require is not defined in ES module scope, you can use import instead
TypeScript's own CommonJS syntax fails earlier, when the file is transformed:
import os = require("node:os");
console.log("ok", typeof os.platform);
Error: Failed to transform …/entry.ts:
! TS(1202): Import assignment cannot be used when targeting ECMAScript modules.
tsc compiles this to const os = require("node:os");.
The same happens to a CommonJS .ts file imported from an ES module, and to test files run with --test. module: node20 is not affected, because there the package type already decides.
Cause
default_module_from_tsconfig (src/lib.rs) groups node16, node18 and nodenext with the ES module settings (es6, es2015 … esnext). That makes the resolve hook report every .ts/.tsx file as an ES module under those settings.
- Lingua principale
- TypeScript
- Stelle
- 275
- Fork
- 10
- Merge medio
- 5h 31m
- PR unite (30g)
- 68
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
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 oxc-project/oxc-node
-
Clarify module resolution with .ts files using import and package.json type commonjsForse già presa @darcyrush l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
oxc-project/oxc-node#905 ·
I maintainer di solito rispondono entro 1 giorno
-
.ts files whose only imports and exports are type-only run as ES modules, without require or moduleForse già presa @darcyrush l’ha presa 2 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
oxc-project/oxc-node#909 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 53/100
oxc-project/oxc-node#906 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
oxc-project/oxc-node#891 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
oxc-project/oxc-node#449 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di oxc-project/oxc-node
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 91/100
marimo-team/marimo#11768 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue priority: high size: XS
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
openclaw/openclaw#195577 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
[Studio feedback] 对话内容向下滚动时执行过程吸顶时,由于背景色是透明的,导致执行过程标题与下面的具体执行内容重叠,导致了两行信息重叠显示;建议执行过程的背景色设置为会话界面的背景Apertabug from-studio
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
esengine/DeepSeek-Reasonix#15044 ·
I maintainer di solito rispondono entro 1 giorno
-
Web wizard: "Launch without Sandbox" can switch a Structured create to Terminal in the same clickApertaarea:web bug needs-triage P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
agent-of-empires/agent-of-empires#5489 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno