Skip to content

Monorepo / workspaces imports attempt to reference rootDir / outDir literally instead of package path reference #45964

Closed
@Codex-

Description

@Codex-

Bug Report

🔎 Search Terms

Monorepo workspaces
import from distribution instead of source
auto-import from package not source
import from source incorrectly

🕗 Version & Regression Information

  • This is the behavior in every version I tried, from 4.1.* to 4.4.3

💻 Code

When trying to resolve a packages exports the paths do not resolve as a normal packages would, except for the case of the index, where it instead tries to use either the outDir or the rootDir.

I have created a minimum reproduction of the issue here: https://github.com/Codex-/monorepo-issue

Does not work:

// These imports should resolve the generated package structure:
import { name as catName } from "@monorepo-issue/dep-a/cat/cat";
import { name as dogName } from "@monorepo-issue/dep-a/dog/dog";
import { isEvil } from "@monorepo-issue/dep-a/eggman/eggman";

Works when referenced via the outDir:

// Importing from generated lib works:
import { name as catName } from "@monorepo-issue/dep-a/lib/cat/cat";
import { name as dogName } from "@monorepo-issue/dep-a/lib/dog/dog";
import { isEvil } from "@monorepo-issue/dep-a/lib/eggman/eggman";

Works when referenced via the rootDir:

// Importing from src works:
import { name as catName } from "@monorepo-issue/dep-a/src/cat/cat";
import { name as dogName } from "@monorepo-issue/dep-a/src/dog/dog";
import { isEvil } from "@monorepo-issue/dep-a/src/eggman/eggman";

🙁 Actual behavior

When importing from these monorepo/workspaces packages the path should be that of the package import path, opposed to the source:
image

(Should not have src but instead the package path of @monorepo-issue/dep-a/eggman/eggman)

🙂 Expected behavior

I would expect that as this is imported to main as a package, it would behave like a package and the imports to be valid without requiring the full path including the package root and either the outDir or rootDir.

I'm hoping this is a simple repository configuration issue, from the way workspaces and package references are described I would expect this to work as described above though.

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