Skip to content

Auto-import prefers parent index.ts which leads to circular reference #45953

Closed
@gordonmleigh

Description

@gordonmleigh

Bug Report

This appears to be recently changed behaviour. I have a package with an index.ts at the root:

  1. I write a file a/Foo.ts which contains export const Foo = 'Foo'
  2. I write a root index.ts which contains export * from './a/Foo'
  3. I write a file b/Bar.ts and attempt to auto-import Foo
  4. The import is written as import { Foo } from '..'.

I think that importing from an index directly above the file like this is highly likely to lead to a circular reference.

🔎 Search Terms

auto-import auto-import relative

🕗 Version & Regression Information

  • This changed between versions 4.3.5 and 4.4.2

⏯ Playground Link

See simple repro.

💻 Code

// index.ts
export * from './a/Foo';
// a/Foo.ts
export const Foo = 'Foo';
// b/Bar.ts
import { Foo } from '..'; // this is the resulting import

const Bar = Foo; // try to auto-import this

🙁 Actual behavior

Imports from parent index.ts. This file is highly likely to also import the importing file, causing a circular reference.

🙂 Expected behavior

Import from './a/Foo' instead. Or, put another way, prefer not to import from a path which has only one or more .. in it.

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions