tl;dr
It can be done: GitHub - arggh/meteor-yarn-workspaces
I was always under the impression that Meteor doesn’t really play nice in monorepos. There’s been many posts on Github and this forum where people have trouble & requests for Meteor to support looking up node_modules
higher up in the folder hierarchy to work with eg. Yarn Workspaces, such as
-
Allow imports from directories above Meteor project root · Issue #8344 · meteor/meteor · GitHub
-
💰 Meteor products that make money - #27 by jamesmillerburgess
We use a monorepo with several non-Meteor packages, but we can’t find a way to make this work with
lerna
oryarn workspaces
. So we are usingyalc
at the moment, but this has other compatibility issues and complicates our CI setup -
and finally Resolving npm modules from node_modules higher in parent folders · Issue #9000 · meteor/meteor · GitHub
…where houshuang
wrote:
The new Yarn workspaces feature to make it easier to work with monorepos relies on hoisting common npm packages to the parent directory. Apparently this is part of the npm specification, that it will resolve by looking into the current node_modules, but also in node_modules in the parent folder. This works with node, and Webpack. However, Meteor’s bundler only looks for modules in the current node_modules folder, and when it cannot find it, it errors out. (Version METEOR@1.6-beta.16).
We have our Meteor app organized as a mono-repo with several plugin packages that are required by the Meteor app. We used to use symlinking (which works well), but are looking at transitioning to the yarn workspace model (much faster install, less hand-written scripts).
…to which @benjamn replied:
Meteor does not, and will not ever, consider node_modules directories outside your application root directory, because that would require you to somehow recreate that surrounding environment on the server where you deploy your app. The app should be self-contained.
…Which was a bummer at the time.
Luckily, later Yarn has introduced a nohoist
configuration option, which allows us to use Yarn Workspaces and benefit from hoisting, except for the Meteor apps, which still want their modules strictly inside app directory’s own node_modules
. That’s why the nohoist
option is needed.
And it works, no manual symlinking or scripts required.
I created this little demo repo to test different solutions for working with Meteor in monorepos, next up is Npm@7 and Yarn@2. Sadly Meteor doesn’t (yet ) support pnpm at all.
Anyway, just thought I’d share.