Quick Answer

Fix module import issues.

Understanding the Issue

Occurs when importing from files that TypeScript doesn't recognize as modules.

The Problem

This code demonstrates the issue:

Typescript Error
import { x } from "./non-module"; // Error

The Solution

Here's the corrected code:

Typescript Fixed
// Solution 1: Add export to file
// non-module.ts:
export const x = 42;

// Solution 2: Use type declaration
declare module "./non-module" {
  export const x: number;
}

// Solution 3: Import entire file
import * as stuff from "./non-module";

// Solution 4: Check tsconfig.json
// Ensure "module" is set appropriately (e.g., "CommonJS", "ES2015")

Key Takeaways

Ensure files have proper exports and module systems are configured.