Error AtlasError Documentation and Resolution

File is not a module

File '{0}' is not a module.

An import resolves to a file that TypeScript treats as a script rather than an importable module. This commonly occurs when a local helper file has declarations but no exports.

TS2306build
File '{0}' is not a module.
  • A helper file contains declarations without imports or exports and is treated as a script.
  • An import points to an empty or unintended file.
  • A declaration file describes globals but is being consumed as though it exports named members.
  1. Check the file path in the diagnostic before editing compiler options. Confirm it is the file you intended to import.
  2. If a helper should be imported, export it explicitly: export const limit = 10 in limits.ts pairs with import { limit } from './limits'.
  3. Use export {} only when the goal is module scope without exported members. It does not expose existing declarations and will not make a named import valid.
  4. For a global declaration file, decide whether the types should remain global or become module exports. Adding export {} changes scope, so do not apply it blindly to existing ambient declarations.
  5. Run the project type checker again and verify any consumers of the changed declarations. Module detection also depends on compiler configuration, so compare the editor's project with the command-line project if results differ.
TypeScript Handbook: Modules
Fix TS2306: File is not a module in TypeScript | Error Atlas