21

Working on a larger typescript project we decided to move the code to a monorepo with yarn workspaces.

We use webpack to build and bundle and everything works well (especially the linking between local modules/packages).

Since yarn workspaces will store most of the node_modules in the mono repo's root folder, the IDE (IntelliJ as well as VSCode) have problems resolving the imports to any node_modules when coding inside a "inner" project (so called "package" of a monorepo).

The strange thing is that imports are not known but on the other hand most of the time you can navigate to the correct source / definition within the IDEs for the same import if you write it down manually.

We have tried to tell IntelliJ to look into another folder for node_modules, but still not satisfying.

Please share your experience with yarn workspaces / monorepo (e.g. lerna) and how you develop the code living in these monorepos.

Which IDE do you use?

Did you add any special configurations to the IDE and/or package.json, tsconfig.json?

1

4 Answers 4

4

https://github.com/Izhaki/mono.ts

It uses yarn workspaces and marry well with VSCode. I hope the README is clear enough.

Basically, use two (parallel) typescript configuration trees:

  • Pre-build - uses aliases (for VSCode, tests, webpack, etc).
  • Build - uses typescript 3 project references for publishing essentially.
3

IDEA doesn't provide any support for Yarn workspaces; if you miss it, please follow WEB-29250 and linked tickets for updates. You can try adding path mappings to your tsconfig.json - see https://intellij-support.jetbrains.com/hc/en-us/community/posts/207656825/comments/115000529564

0
3

Upodate as of 2018.1.1 IntelliJ now supports yarn workspaces so if you use this there should not be a problem.

https://blog.jetbrains.com/webstorm/2018/04/webstorm-2018-1-1/

1

Please share your experience with yarn workspaces / monorepo (e.g. lerna) and how you develop the code living in these monorepos.

Which IDE do you use?

Since you are asking. I basically ran into the same issues as you did. One solution I was looking into was disable hoisting node modules as described here. Unfortunately it seems it is not yet in the stable release.

What I ended up was ditiching workspaces for now until they fix either the IDE or release the nohoist option. Instead I am using lerna for now. It is less convenient but it does not hoist so that both the build tools and the IDE are satisfied.

Oh, I am also using IntelliJ (ultimate)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.