question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Path based Code navigation to /index.js seems broken

See original GitHub issue
  • 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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
IllusionMHcommented, Mar 3, 2020

That’s Node.js “feature” to check folder/index.js if folder referenced, using "moduleResolution": "node" should enable this behavior in TS.

However this won’t help with e.g. index.android.js but I doubt that since this should be handled by tooling, maybe vscode-react-native might handle these specific cases.

0reactions
ortacommented, Mar 4, 2020

I think so yeah, it could recommend making a jsconfig with target: node?

Perhaps something like?

import SomeComponent from ...'common-lib/Router'

/// TS:XYZ - Could not find a file at 'common-lib/Router', but  `common-lib/Router/index.js` was found - do you want to set `moduleResolution: node`?
Read more comments on GitHub >

github_iconTop Results From Across the Web

4 Reasons Why Your Source Maps are Broken - Sentry Blog
Just like sourceMappingURL , if this value is a relative path, it is relative to the path location of the bundled JavaScript file....
Read more >
24 - Stack Overflow
I was installing a react startup app and added Webpack, but it says Can't resolve './src/index.js' . Browser Shows My app gives this...
Read more >
Code-Splitting - React
If you're using Create React App, Next.js, Gatsby, or a similar tool, ... The best way to introduce code-splitting into your app is...
Read more >
z-index - CSS: Cascading Style Sheets - MDN Web Docs
The z-index CSS property sets the z-order of a positioned element and its descendants or flex items. Overlapping elements with a larger ...
Read more >
Next.js 13: Working with the new app directory - LogRocket Blog
The UI for a particular route is defined with a page.jsx file inside of the folder. Therefore, a folder structure that looks like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found