Using `"allowJs": true` and `"module": "commonjs"` to transform `.mjs` files should emit `.cjs` files
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 42/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
Direzione di ricerca
Riproduci il problema con package.json, tsconfig.json, src/javascript.mjs e src/typescript.ts riportati nel report, quindi esegui gli script di build e test. Confronta le estensioni e i formati dei moduli emessi in dist; il lavoro è completato quando l’input .mjs trasformato in CommonJS viene emesso con un’estensione valida per quel formato, con una copertura per il comportamento scelto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Report
🔎 Search Terms
CommonJS, allowJS, ESM, CJS, file extensions
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about output "file extensions for CommonJS modules".
⏯ Playground Link
Sandbox link with relevant code (I couldn't use the playground, since this involves using an .mjs file).
💻 Code
// package.json
{
"name": "tsc-mjs-extension-bug",
"version": "0.1.0",
"type": "commonjs",
"main": "dist/javascript.mjs",
"scripts": {
"build": "tsc",
"test": "node ."
},
"dependencies": {
"typescript": "5.1.3"
}
}
// tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "nodenext",
"allowJs": true,
"outDir": "dist"
}
"include": ["src"]
}
// src/javascript.mjs
export const where = "javascript";
console.log(`Hello ${where}`);
// src/typescript.ts
export const where = "typescript";
console.log(`Hello ${where}`);
🙁 Actual behavior
The javascript.mjs is transformed to CommonJS (as expected), but the file extension of the emitted file is still .mjs.
This breaks the package, since .mjs is supposed to be use exclusively for JavaScript using ESM and the emitted file now uses CommonJS.
🙂 Expected behavior
I would expect tsc to transform the src/javascript.mjs to CommonJS and either:
- emit it as
dist/javascript.cjsor alternatively - take into account the
"type": "commonjs"in the package.json and emit the file as.jsas it does with thesrc/typescript.tsfile.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Guida per i contributori
Apri 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 microsoft/TypeScript
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
microsoft/TypeScript#64322 · 2 commenti · 1 reazione · 2 assegnatari ·
-
Possible Improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/TypeScript#64278 · 1 commento · 1 reazione ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
microsoft/TypeScript#64118 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
microsoft/TypeScript#64094 ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/TypeScript#63959 · 5 commenti ·
Tutte le issue di microsoft/TypeScript
Issue simili
-
optimization optimization:agents-md-curator
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
blinklabs-io/bursa#904 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 commenti ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100