[bug]: build ignores exports file names and package.json#type, breaking "type": "module" plugins
I maintainer di solito rispondono entro 6 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, typescript, vite
- Ambito
- build-system, cli, tooling
Direzione di ricerca
Start in src/cli/commands/utils/build/vite-config.ts and run strapi-plugin build with the package.json exports and type settings from the reproduction. Done means import and require outputs use the exact exports paths, including .js, .cjs, or .mjs, and validation accepts ESM-only or CJS-only plugins.
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
What's Wrong?
strapi-plugin build ignores the file names in the package.json exports map and the package's "type". It reads the import / require paths only to pick the output directory, then always writes index.mjs (ESM) and index.js (CommonJS):
// src/cli/commands/utils/build/vite-config.ts
const outputPath = bundle.output.cjs ?? bundle.output.esm;
const outDir = path.dirname(outputPath);
// ...
fileName: (format) => (format === 'es' ? 'index.mjs' : 'index.js'),
This makes "type": "module" plugins impossible to build correctly:
- Dual build: CommonJS always lands in
index.js. In a"type": "module"package Node loads that file as ESM, so Strapi fails at boot withexports is not defined in ES module scope. Pointingrequireat./dist/server/index.cjsdoesn't help: the build still writesindex.js, andindex.cjsnever exists. - ESM-only build: a plugin with only
import/defaultand norequireis rejected before building, because./strapi-adminand./strapi-servermust declare bothimportandrequire:
If that check were removed, the ES output would still be written toexports["./strapi-server"].require is a required fieldindex.mjs, not to theimportpath.
To Reproduce
- Create a plugin with
"type": "module"and:"exports": { "./strapi-server": { "source": "./server/src/index.js", "import": "./dist/server/index.js", "require": "./dist/server/index.cjs", "default": "./dist/server/index.cjs" }, "./package.json": "./package.json" } - Run
strapi-plugin build. dist/servercontainsindex.js(CommonJS) andindex.mjs. Neither file matches the exports map, andindex.cjsis missing.- Load the output:
node --input-type=module -e "import('./dist/server/index.js')"exports is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and '…/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
For the ESM-only case, drop require and set "default": "./dist/server/index.js". Step 2 then fails with the validation error above.
Expected Behaviour
- Each output file is written to the exact path its exports condition points at (
importfor ESM,requirefor CommonJS). The.cjs/.js/.mjsextension the author picked for their"type"is then respected. ./strapi-adminand./strapi-serverneed at least one ofimportorrequire, not both, so ESM-only (and CJS-only) plugins can be built.- Optionally,
buildwarns when an extension makes Node load the file in the wrong format, e.g.require→.jsin a"type": "module"package.
init writes "type": "commonjs" with index.mjs / index.js, which stays correct under this behaviour.
Related: #241 (type declarations have the same one-file-for-both-formats problem).
I have a fix with tests in a fork and can open a PR.
- 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
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
strapi/sdk-plugin#241 ·
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
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
AykutSarac/jsoncrack.com#616 ·
-
nip27: long hashtag swallows the rest of the content, lone # gives an empty hashtagForse già presa @bardrop l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
nbd-wtf/nostr-tools#578 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
backnotprop/plannotator#3427 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
microsoft/Power-CAT-Copilot-Studio-Kit#942 ·
I maintainer di solito rispondono entro 1 giorno
-
[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