Skip to content

import/order not working with @types packages #1552

@peoplenarthax

Description

@peoplenarthax

Hello,

We are trying to work around import/order for our codebase but we face some difficulties as it seems that some external dependencies are recognised as internal.

We are using typescript and this makes imports a bit more peculiar, as when we try to import a package without types we most likely use the @types package for it (if it exists). This brings 2 problems:

  • First one, packages like react when analysing the path will be in a path like: ../../node_modules/@types/react instead of ../../node_modules/react, hence the path.indexOf function will fail as node_modules/react can't be found. We could say that there is a workaround this using import/external-modules-folder setting, pass both node_modules and node_modules/@types and it works. But this does not solve our second issue:

  • When a package with a name such as @loadable/component does not export types and we need to fetch it from @types, there is a impossibility to declare 2 workspaces ( @types/@loadable/component), and so it instead becomes @types/loadable__component. Which breaks the rule that try to find @loadable/components in the path.

Is there a work around this? I feel that to classify if a path is external it should be enough by checking if the folder directory appears in the path instead of check for folder\package what requires you to start having workarounds.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions