You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript has a simple guess on whether the input file is in es modules or global script by seeing it includes keywords like import, export. So an empty file becomes non-esm and triggers an error ts(1208): 'file.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module..
However, as you may know empty files are also valid es modules. I think it is safe to remove this error/warning and just treat an empty file as in esm.
Rollup and esbuild also treat empty files as ESM too.
🔍 Search Terms
IsolatedModules, empty, esm, warning.
✅ Viability Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
Suggestion
TypeScript has a simple guess on whether the input file is in es modules or global script by seeing it includes keywords like
import
,export
. So an empty file becomes non-esm and triggers an errorts(1208): 'file.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
.However, as you may know empty files are also valid es modules. I think it is safe to remove this error/warning and just treat an empty file as in esm.
Rollup and esbuild also treat empty files as ESM too.
🔍 Search Terms
IsolatedModules, empty, esm, warning.
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Treat empty files as es modules when "IsolatedModules" is on.
📃 Motivating Example
💻 Use Cases
The text was updated successfully, but these errors were encountered: