We have a monorepo that uses Yarn’s ‘workspaces’ feature, meaning that whenever possible, Yarn will hoist dependencies to the monorepo's root node_modules
directory rather than keep them in the individual package's node_modules
dir. This relies on Node’s module resolving algorithm, which continues to search for modules in node_modules
directories up the dir tree until it finds the required module.
When using Flow types in a file that imports another package (internal or external to the monorepo), running Flow inside the package that contains that file causes a Cannot resolve <package-name>
error to be thrown. It seems like Flow uses a different module resolving algorithm, and fails since the installed modules are hoisted to the root dir and Flow does not continue to search up the dir tree.
Is there a way around this other than running Flow from the root? Running from the root is less than optimal because it does not allow different settings for different packages in the monorepo.
Node version: 10.8.0flow-bin
version: 0.78.0
With workspaces since the dependencies are locked from root, you just need to do a yarn at the top-level. For workspaces to work, your “workspace” folders need to have a package.json that contain a name and version. To run commands in a single package in your monorepo, use the following syntax:
Previously, we wrote about monorepos and how Yarn Workspaces makes working with them simpler. Unfortunately, moving to a monorepo is not always an easy choice. Without the right tooling, a monorepo can often harm the developer experience instead of help it.
It’s monorepo. If you’re not aware of monorepo benefits and flaws check this article out. Yarn is fast. Yarn stores packages in a cache. Yarn is parallel. But what about Yarn workspaces? That’s how Yarn explains them:
To run commands in a single package in your monorepo, use the following syntax: $ yarn workspace example-1 run test yarn workspace v1.x.x yarn run v1.x.x $ node test.js test from example 1 ✨ Done in 0.23s. ✨ Done in 0.86s.
I also ran into this problem
To fix it need update .flowconfig
:
[include]
../../node_modules/
FS struct:
/project_root
--/node_modules
--/packages
----/module1
------.flowconfig
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With