@rollup/plugin-virtual: TS2349: This expression is not callable under modern "moduleResolution": "NodeNext"
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, typescript
- Ambito
- build-system, tooling
Direzione di ricerca
Inizia con packages/virtual/package.json e packages/virtual/types/index.d.ts, quindi esamina l’import NodeNext nel contesto src/index.ts indicato. Verifica le mappature dei tipi import e require del package compilando l’esempio con impostazioni moderne di TypeScript; l’attività è completata quando l’import predefinito viene riconosciuto come chiamabile senza TS2349.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
- Rollup Plugin Name: @rollup/plugin-virtual
- Rollup Plugin Version: latest
- Rollup Version: latest
- Operating System (or Browser): macOS
- Node Version: v24.18.0
- Link to reproduction (⚠️ read below): I'm providing the exact type error context below. This is a static type resolution failure in TypeScript rather than a runtime execution bug.
Expected Behavior
When importing the plugin into a project using modern TypeScript settings ("moduleResolution": "NodeNext" or "Node16"), the default import should be recognized as a callable function:
import virtual from '@rollup/plugin-virtual';
export default {
plugins: [
virtual({ 'virtual-module': 'export default "hello";' })
]
};
Actual Behavior
The TypeScript compiler throws a compilation error preventing the build from running:
src/index.ts:59:13 - error TS2349: This expression is not callable.
Type 'typeof import(".../node_modules/@rollup/plugin-virtual/types/index")' has no call signatures.
59 virtual({
~~~~~~~
Additional Information
The issue stems from a combination of the package layout configuration inside packages/virtual/package.json and packages/virtual/types/index.d.ts.
Why this happens
The plugin's package.json exports a single top-level typings statement:
"exports": {
"types": "./types/index.d.ts",
"import": "./dist/es/index.js",
"default": "./dist/cjs/index.js"
}
Because the package does not explicitly include "type": "module", TypeScript's NodeNext engine treats ./types/index.d.ts as a CommonJS declaration file.
Under a CommonJS environment interpretation, TypeScript reads export default function virtual as an object property wrapper ({ default: function }) instead of a root-level callable default function export. As a result, the default import resolves to the module namespace object instead of the callable function, breaking execution under strict TypeScript configurations.
Fix
Provide separate type mappings for ESM and CJS hooks within exports so TypeScript evaluates them in their matching format context:
- Copy
packages/virtual/types/index.d.tsto a dedicated.d.mtsversion. - Update the
exportsconfiguration block inpackages/virtual/package.json:"exports": { "import": { "types": "./types/index.d.mts", "default": "./dist/es/index.js" }, "require": { "types": "./types/index.d.ts", "default": "./dist/cjs/index.js" } }
- Lingua principale
- JavaScript
- Stelle
- 3.8k
- Fork
- 635
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
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 rollup/plugins
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Support js-yaml v5 Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
-
Babel 8 support Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
Tutte le issue di rollup/plugins
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Daemon passes --experimental-wasm-jspi unconditionally on Node >= 24; Node 26 rejects the flag Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Automattic/studio#4908 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
sugarlabs/musicblocks#8847 ·