Custom import paths in a monorepo

I am working on a monorepo project where I have several JavaScript packages. Here is an example project: https://github.com/bensampaio/phpstorm-example (just run yarn to set it up).

PhpStorm 2017.3.4 can resolve the imports in packages/a/src/index.js and packages/b/src/index.js. However, PhpStorm Auto Import feature uses relative paths instead of package based imports. I found several issues about this but I found the instructions quite confusing and nothing I tried really worked for me. What I would like auto import to do is:

  • If a module in packages/a imports another module from packages/a then a relative path would be used to import it (../path/to/module).
  • If a module in packages/a imports another module from packages/b then a package import would be used (@my/b/path/to/module).

Is this possible? If not are there similar alternatives?

I found something about a jsconfig.json. Do I need this file? If yes, where should I put it to achieve what I want?

Thank you!

 

5 comments
Comment actions Permalink

PhpStorm provides no support for yarn workspaces/monorepo projects; no suitable workarounds can be suggested. Please follow https://youtrack.jetbrains.com/issue/WEB-29250 and linked tickets for updates

 

>I found something about a jsconfig.json. Do I need this file?

No; this file is a VSCode configuration file used for setting up its JavaScript language service; PhpStorm doesn't make any use of it

 

2
Comment actions Permalink

I see that https://youtrack.jetbrains.com/issue/WEB-29250 is fixed. I have now installed PHPStorm 2018.1.6 but I keep having this issue. Do I need some extra configuration or is my specific issue not fixed yet?

0
Comment actions Permalink

Seems the fix doesn't affect auto-imports; logged as https://youtrack.jetbrains.com/issue/WEB-33884, please follow it for updates

0
Comment actions Permalink

Any update on this since 2018? It will be great to be able to resolve multiple webpack configs for a yarn worksapces/monorepo.

0
Comment actions Permalink

https://youtrack.jetbrains.com/issue/WEB-33884 was fixed 2 years ago...

Multiple webpack configuration files are not yet supported, please follow https://youtrack.jetbrains.com/issue/WEB-29578 for updates

0

Please sign in to leave a comment.