Skip to content

Feature: disable extensionless imports #28288

Closed

Description

I'd like there to be a way to always require the file extension to be specified for relative import statements. At the moment extensionless imports always just work. Even 'Go to Definition' just assumes it should open the JS file.

src/
 - index.js
 - foo.js
// index.js
import { Foo } from './foo'; // extensionless

I'd like there to be a jsconfig option to disable this behavior and require a file extension to be specified.

import { Foo } from './foo';
                    ^^^^^^^ No definition found for 'foo'
// fix
- import { Foo } from './foo';
+ import { Foo } from './foo.js';

I'm asking because extensionless imports don't really work in the browser if you're not using a module bundler. It can only work if the HTTP server supports extensionless imports, which is a big ask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Domain: ES ModulesThe issue relates to import/export style module behaviorIn DiscussionNot yet reached consensusNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions