Skip to content

Incorrect "Cannot find name" when importing default value #26391

Closed

Description

TypeScript Version: 3.0.1

Search Terms: Cannot find name import default

Code

// fetch.d.ts
declare function fetch(url: string): Promise<any>;
export = fetch;
declare namespace fetch {
  export { fetch as default };
}

// index.ts
import f from "./fetch";
f("url"); // error TS2304: Cannot find name 'f'

Expected behavior: Name should be found

Actual behavior: Cannot find name. Interestingly import { default as f } from "./fetch"; works.

Playground Link: (It doesn't support modules :/)

Related Issues: Couldn't find one

Activity

  1. ghost added
    BugA bug in TypeScript
    on Aug 12, 2018
  2. IIIristraM commented on Aug 17, 2018

    @IIIristraM

    I also face the issue with default import from a js file with exports.default = Component. import Component from '...' worked fine in version 2.8.4 Now it woks only with import {default as Component} from '...'.

    There is "allowSyntheticDefaultImports": true in my tsconfig, setting option to false resolves the issue, but creates much more troubles in my project.

    Probably this is related issue.

  3. RyanCavanaugh commented on Jul 23, 2025

    @RyanCavanaugh
    Member

    This appears to be fixed now

  4. locked as resolved and limited conversation to collaborators on Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions