microsoft / microsoft/TypeScript

Path based Code navigation to /index.js seems broken

Open
#37,189 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

  • VSCode Version: 1.42.1
  • OS Version: Mac OS

Steps to Reproduce:
Code navigation seems broken when you import by path and the file is actually in an index.js file.
There are a couple of scenarios relevant to developing in react-native

  1. import from another package in a monorepo import SomeComponent from 'common-lib/Router, when the file is packages/common-lib/src/Router/index.js
  2. import in the same package import SomeComponent from 'modules/Router, when the file is src/modules/Router/index.js
  3. import SomeComponent from 'modules/Router, when the file is not actually index.js src/modules/Router/index.ios.js and src/modules/Router/index.android.js

In general, what works is loading a file name by name (not an index.js file)
What doesn't work is loading a file by path that is actually an index.js, index.native.js, index.ios.js, index.android.js etc file

My code structure is

root
    packages
           mobile
           server
                src
                       server
                       shared
           common-lib

There is some history here that is not ideal. But ok.

packages/server jsconfig.json

{
	"compilerOptions": {
		"target": "es2017",
		"allowSyntheticDefaultImports": false,
		"baseUrl": ".",
		"paths": {
			"common-lib/*": ["../common-lib/*"],
			"mobile/*": ["../mobile/*"],
			"modules/*": ["./src/shared/modules/*"],
			"components/*": ["./src/shared/components/*"],
			"router/*": ["./src/shared/router/*"],
			"server/*": ["./src/server*"],
			"App": ["./src/App"]
		}
	},
	"exclude": ["node_modules", "../../node_modules", "build"]
}

Does this issue occur when all extensions are disabled?: Yes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the three import cases with the provided packages/server jsconfig.json, including index.js and platform-specific index files. Trace code navigation for path-based imports and compare it with named-file imports; done means navigation reaches the resolved module in each listed scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
developer-experience, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.