Skip to content

Better error message when users mistakenly import from named vs. default export #13601

Closed
@alexeagle

Description

@alexeagle

At google, we've had a number of users trip over import syntax when working with libraries that have default exports.

Given this scenario:

has_named_export.ts

export var a = 1;

has_default_export.ts

var b = '';
export default b;
  1. Users often do:
import {b} from './has_default_export';

which gives:
Error: module has no exported member 'b'

Request: the error could be more helpful, like "did you mean to import the default export, with no curly braces"
This is especially likely when the name of the default export matches the named import.
Novice users look at has_default_export and think that B should be importable, and may never have worked with default exports.

  1. Also possible:
import a from './has_named_export';

"has_named_export" has no default export

This one is less frequent, but it could say "did you mean to import the named import 'a' by using curly braces"

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingFixedA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions