[bug]: one .d.ts serves both import and require outputs, so types masquerade as CJS for ESM consumers
I maintainer di solito rispondono entro 6 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- typescript, vite
- Ambito
- build-system, cli, tooling
Direzione di ricerca
Start with the vite-plugin-dts setup in build, then trace the default exports map written by init and the export checks in verify. Reproduce the issue with src/__tests__/fixtures/typescript-plugin and @arethetypeswrong/cli. Done means import and require conditions point to declarations in matching formats, and verification accepts the nested exports map.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What version of @strapi/sdk-plugin are you using?
@strapi/sdk-plugin6.1.1 (also currentmain)- Node.js 24.21.0
- TypeScript 5.x (checked with
@arethetypeswrong/cli0.18.5)
What's Wrong?
strapi-plugin build emits a single declaration file per bundle (dist/admin/src/index.d.ts, dist/server/src/index.d.ts), and the exports map generated by init points one top-level types condition at it for both the import (index.mjs) and require (index.js) outputs:
"./strapi-server": {
"types": "./dist/server/src/index.d.ts",
"source": "./server/src/index.ts",
"import": "./dist/server/index.mjs",
"require": "./dist/server/index.js",
"default": "./dist/server/index.js"
}
TypeScript decides a .d.ts file's module format from the nearest package.json#type. In a "type": "commonjs" plugin (what init generates), that one .d.ts is read as CommonJS, so ESM consumers resolving under node16/nodenext get CommonJS types for an ES module. Are the Types Wrong reports this as 🎭 Masquerading as CJS for both ./strapi-admin and ./strapi-server.
In a "type": "module" plugin the same layout flips the problem: the .d.ts is read as ESM, so require consumers would get ESM types (Masquerading as ESM).
To Reproduce
Using the repo's own typescript-plugin test fixture:
- Copy
src/__tests__/fixtures/typescript-pluginsomewhere outside the repo. - Build it with
strapi-plugin build. - Run
npx @arethetypeswrong/cli --pack .in that directory.
Output:
│ node10 │ node16 (from CJS) │ node16 (from ESM) │ bundler
"@strapi/plugin-test/strapi-admin" │ 💀 Resolution failed │ 🟢 (CJS) │ 🎭 Masquerading as CJS │ 🟢
"@strapi/plugin-test/strapi-server" │ 💀 Resolution failed │ 🟢 (CJS) │ 🎭 Masquerading as CJS │ 🟢
(The node10 failure is expected for an exports-only package with no top-level main/types. This issue is about the node16 (from ESM) column.)
Expected Behaviour
Each output format gets declarations TypeScript reads in the matching format, and the exports map points to them per condition, for example:
"./strapi-server": {
"source": "./server/src/index.ts",
"import": {
"types": "./dist/server/src/index.d.mts",
"default": "./dist/server/index.mjs"
},
"require": {
"types": "./dist/server/src/index.d.ts",
"default": "./dist/server/index.js"
},
"default": "./dist/server/index.js"
}
i.e. .d.mts next to ESM output and .d.ts / .d.cts next to CommonJS output, chosen to match package.json#type. ESM-only or CJS-only plugins keep a single declaration file in the right format.
This would touch:
- the
vite-plugin-dtssetup inbuild(emit declarations per format), - the default exports map written by
init, verify's export checks, which currently expect a top-leveltypesfirst and flat stringimport/requirevalues.
- Lingua principale
- TypeScript
- Stelle
- 24
- Fork
- 13
- Merge medio
- 5g 3h
- PR unite (30g)
- 5
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna 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 strapi/sdk-plugin
-
Difficoltà 4/5 Mezza giornata Idoneità per principianti 15/100
strapi/sdk-plugin#244 ·
I maintainer di solito rispondono entro 6 giorni
-
[bug]: build ignores exports file names and package.json#type, breaking "type": "module" pluginsForse già presa @unrevised6419 l’ha presa 44 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
strapi/sdk-plugin#242 ·
I maintainer di solito rispondono entro 6 giorni
-
[feat]: build a subset of bundles with --bundle, for per-bundle task cachingForse già presa @unrevised6419 l’ha presa 51 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
strapi/sdk-plugin#238 ·
I maintainer di solito rispondono entro 6 giorni
-
[bug]: When building with latest sdk-plugin version, I loose sub folders typesForse di nuovo libera @jhoward1994 l’ha presa 247 giorni fa e non c’è nessuna pull request aperta. Apertaissue: bug
strapi/sdk-plugin#115 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 6 giorni
-
issue: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 58/100
strapi/sdk-plugin#111 · 2 commenti ·
I maintainer di solito rispondono entro 6 giorni
Tutte le issue di strapi/sdk-plugin
Issue simili
-
[BUG]: Duplicate preposition in heading and unformatted feedback text on Strengthen Argument pageApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
AOSSIE-Org/DebateAI#801 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
ci: repo has no GitHub Actions workflow, so pushes and pull requests are never built or testedApertaagents area: runtime automation chore cli consistency dependencies developer-experience difficulty: easy documentation enhancement good first issue help wanted hygiene json-output priority: P3 starters tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Add: BOM CineApertaapproved check:passed streams:add
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno