Skip to content

Auto-import path of node module does not use the package nameΒ #54023

@hanzooo

Description

@hanzooo

Bug Report

πŸ”Ž Search Terms

  • Auto-import
  • Code Fix
  • Quick Fixes
  • Completion

πŸ•— Version & Regression Information

  • This is a expected behavior about auto import or code fix.

⏯ Playground Link

πŸ’» Code

// node_modules/my-pkg/package.json
{
     "name": "my-pkg",
     "version": "1.0.0",
     "main": "lib", // some node_modules may use directory to be the entry point, and node.js can handle it (will use the lib/index file)
     "module": "lib"
}

// node_modules/my-pkg/lib/index.js
export function foo() {};

// index.ts
foo();

πŸ™ Actual behavior

When apply code fix using vscode at foo, it will suggest import { foo } from 'my-pkg/lib', which my-pkg/lib is not the best path name.
image

πŸ™‚ Expected behavior

image

Just like focus at the my-pkg position, we can find the main file xxx/my-pkg/lib/index.js, on the other hand Auto-import should work too.
We expect it to be import { foo } from 'my-pkg'

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