Typescript: Yarn Workspaces IDE Support (IntelliJ, VSCode …)

独自空忆成欢 提交于 2020-07-05 05:56:51

问题


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:


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




回答2:


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:


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/




回答4:


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)



来源:https://stackoverflow.com/questions/47337382/typescript-yarn-workspaces-ide-support-intellij-vscode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!