0

When i'm cmd clicking on a import it can't go to the definition of the component if i use a unnamed default export. It works when I do a named export.

src/components/Component/Component.js

// When i cmd/ctrl click here it should go to OtherComponent.js but it doesn't work
import OtherComponent from 'components/OtherComponent';

const Component = () => null;

src/components/OtherComponent/index.js

export default from './OtherComponent';

/*
if I change it to this it works

import OtherComponent from './OtherComponent';

export default OtherComponent;
*/

src/components/OtherComponent/OtherComponent.js

const OtherComponent = () => null;

export default OtherComponent

My jsconfig

{
    "compilerOptions": {
        "baseUrl": ".",
        "allowSyntheticDefaultImports": false,
        "paths": {
            "*": ["src/*"]
        }
    }
}
Rane
  • 255
  • 1
  • 6
  • 17
  • This is the reason I typically advise against using `export default` - see more information here: https://basarat.gitbook.io/typescript/main-1/defaultisbad – Derek Pollard Oct 21 '20 at 18:49
  • I'm a part of a team, and all the other uses webstorm and it works like a charm for them. I'm trying to get it to work with vs code, and i guess changing how we do this is not an easy solution :) – Rane Oct 21 '20 at 18:54
  • I too use IntelliJ and we have issues with the above; would definitely be interested in how they fixed it – Derek Pollard Oct 21 '20 at 18:56
  • Darek: first mark src as resource or what its called. Right click on the folder. Then Settings -> Code style -> javascript -> import option is called something with relative paths. – Rane Oct 22 '20 at 07:36
  • Yeah, relative/absolute paths work fine...I meant the issue with intellisense and using export default – Derek Pollard Oct 22 '20 at 17:56
  • Any update to make it work with `export default` ? – Bogy Feb 05 '21 at 10:17

0 Answers0