// index.ts
export * from './empty';
and two empty files empty.d.ts
and empty.js
next to it.
🔎 Search Terms
"TS2306"
export * with empty module
"is not a module"
🕗 Version & Regression Information
Happens in 4.4.4, and on all workbench versions.
This is the behavior in every version I tried, and I reviewed the FAQ for entries about "'export *' with empty modules".
⏯ Playground Link
Workbench link with relevant code
💻 Code
// @filename: index.ts
export * from './empty'
// @filename: empty.d.ts
// Comment.
// @filename: empty.js
// Comment.
🙁 Actual behavior
Error:
error TS2306: File 'empty.d.ts' is not a module
I can import empty modules, so why can't I export *
from empty files?
🙂 Expected behavior
The export *
should just be ignored, since the empty module doesn't export anything.
This happens because TS treats files without any imports or exports as script code, not module code. The error should go away if you put export {}
in the empty file.
https://www.typescriptlang.org/docs/handbook/2/modules.html#how-javascript-modules-are-defined
I can't easily do that, as the javascript/typescript files are generated by the protobuf compiler.
But I agree that the behavior seems to defined in the documentation.
Not really sure what to do. Maybe I should file a bug against the protobuf compiler...