Skip to content

Cannot import extensionless #1736

Closed
Closed

Description

@shir0u

If I include the .ts extension, typescript will complain:

TS2691: An import path cannot end with a '.ts' extension

If I don't include the .ts extension, ts-node will complain:

throw new ERR_MODULE_NOT_FOUND(
          ^
CustomError: Cannot find module

Why is this? Why does it work fine for tsc but not ts-node?

Activity

  1. cspotcode commented on Apr 29, 2022

    @cspotcode
    Collaborator

    It doesn't work fine for tsc though, since you get that error.

    https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#type-in-package-json-and-new-extensions

    Relative import paths need full extensions (we have to write import "./foo.js" instead of import "./foo").

    TSC's rule is that it has to be the emitted extension, so it has to be .js. ts-node does the right thing to make this work.

  2. locked and limited conversation to collaborators on Apr 29, 2022
  3. converted this issue into a discussion #1737 on Apr 29, 2022
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions