Skip to content

TS Paths not working with index.ts when using a wildcard - more explained inside #26859

@iangregsondev

Description

@iangregsondev

Hi,

I am using paths to point to another project ( I am using lerna), anyway, I have the following path setup.

    "paths": {
      "@test/pkg2/*": [
        "./packages/pkg2/src/*"
      ],

The problem is that if I do the following, I get an error saying cannot find module.

import {Something} from "@test/pkg2"; // <<<<<<< This errors HERE HERE
import {TestMe} from '@test/pkg2/item/testme' << This is fine

The above error can be fixed by appending index.ts after the /pkg2, but it should know the default package name is index.ts if not is specified.

I can, of course, change the paths to

  "@test/pkg2": [
    "./packages/pkg2/src"
  ],

but now, of course, it complains about not finding testme (see above). The only way I was able to get it to work was by adding both the paths, but is this really correct ?

So, here is what i ended up with, its a lot more code.

   "paths": {
      "@test/pkg2/*": [
        "./packages/pkg2/src/*"
      ],
      "@test/pkg2": [
        "./packages/pkg2/src/"
      ]
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions