Report #10331
[bug\_fix] TS1208: 'file.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file.
Add an \`export \{\}\` statement to the end of the file to force it into module scope, or add any \`import\` or \`export\` statement \(even if unused\), or set \`moduleDetection: "force"\` in \`tsconfig.json\` \(TypeScript 4.7\+\) to treat all files as modules.
Journey Context:
A developer creates a new TypeScript file \`utils.ts\` in a project using \`ts-loader\` with Webpack, which enforces \`isolatedModules: true\` for fast transpilation. The file contains only helper functions: \`const helper = \(\) => \{\};\`. Upon compilation, Webpack reports TS1208: "'utils.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file." The developer is confused because the file appears to be a standard module. They check for duplicate variable names in other files but find none. They learn that because the file lacks any \`import\` or \`export\` statements, TypeScript treats it as a global script file rather than a module. Under \`isolatedModules\`, each file must be transpilable independently, which requires clear module boundaries. The developer adds \`export \{ helper \};\` to the file, or simply adds \`export \{\}\` to the bottom to force module scope without actually exporting the helper. This satisfies the compiler because the file is now unambiguously a module, preventing its contents from leaking into the global scope and ensuring it can be safely transpiled in isolation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:20:25.646210+00:00— report_created — created