I was surprised to discover that Gatsby is able to operate normally as a package within a monorepo, while importing and transpiling source code from other packages in the monorepo with its Webpack config.
Example repo: https://github.com/jedrichards/monorepo-test
My assumption was that Gatsby would treat monorepo packages as it does everything from node_modules and exclude from compilation. Indeed, create-react-app recently backed off this sort of feature for its v2:
We're going to revert monorepo support in favor of consuming library packages via nwb and provide excellent documentation on how to do so.
My example repo above is the simplest case, but I've tested more advanced setups (TypeScript, CSS Modules) and it seems like Gatsby is happily compiling these features found in code in the @monorepo-test/components package (which is resolved via a symlink in the monorepo's root node_modules).
I think it's rather good this just works, but was keen to find out more and whether this is a expected/supported use case before I base a whole set of projects on it. I couldn't find anything about it in the documentation.
gatsby info --clipboard
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.12.0 - ~/.nvm/versions/node/v8.12.0/bin/node
Yarn: 1.13.0-20181004.1524 - ~/.yarn/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v8.12.0/bin/npm
Browsers:
Chrome: 69.0.3497.100
Firefox: 61.0.2
Safari: 12.0
npmPackages:
gatsby: ^2.0.19 => 2.0.29
npmGlobalPackages:
gatsby-cli: 2.4.3
Hiya!
This issue has gone quiet. Spooky quiet. 馃懟
We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
Thanks for being a part of the Gatsby community! 馃挭馃挏
Is this stale, or has the inkteam not reviewed yet? I'd be keen to shed some light on this, although not critical. Feel free to close otherwise.
Hey again!
It鈥檚 been 30 days since anything happened on this issue, so our friendly neighborhood robot (that鈥檚 me!) is going to close it.
Please keep in mind that I鈥檓 only a robot, so if I鈥檝e closed this issue in error, I鈥檓 HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.
Thanks again for being part of the Gatsby community!
I'm evaluating Gatsby in a monorepo environment. I found this issue through a Google search. Thank you for doing a writeup on it :).
I did find this Gatsby blog entry about monorepos on Lerna. I am thinking that if its on the official blog, it means its officially supported.
https://www.gatsbyjs.org/blog/2019-01-01-publish-multiple-gatsby-sites/
@johntran Oh interesting, ty for the blog link! 馃憖
Hi @jedrichards I just found this issue after updating my own issue regarding Gatsby in a monorepo with lerna. The way I got gatsby to work was to add it as a dependency in the project root!
See #11780
Unfortunately I'm having issues with a small handful of plugins, but other than that Gatsby does work in a monorepo
@josefaidt Have a look at my example repo. You might need to use nohoist on Gatsby:
https://github.com/jedrichards/monorepo-test/blob/master/gatsby-app/package.json#L38-L40
Yes I just jumped into that repo and saw that "workspaces": { "nohoist": ["gatsby"] } line. That's really clever, I didn't realize you could do that. I'm going to try this with those other plugins I'm having issues with and see if that resolves it.
@jedrichards how are you able to get this to work?
"workspaces": {
"packages": ["*"]
}
I tried adding this to my workspace and then yarn wouldn't pick anything up until I made it back to an array. I was originally following this piece from the yarn documentation where it claims workspaces should be an array.
That being said I cloned your repo and installed the dependencies (including the ones I was having trouble with) and do not have a single issue.
EDIT: found the blog post where it goes over that spec. Might be time to update their documentation on workspaces 馃槵
@josefaidt I think just ["*"] means yarn will treat any folder in the root as a workspace, i.e. using the * wildcard. So the packages in my example repo are at the top level /gatsby-app and /components. I think your packages _need_ to be at the top level for that to work.
Hiya!
This issue has gone quiet. Spooky quiet. 馃懟
We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contributefor more information about opening PRs, triaging issues, and contributing!
Thanks for being a part of the Gatsby community! 馃挭馃挏
Hey again!
It鈥檚 been 30 days since anything happened on this issue, so our friendly neighborhood robot (that鈥檚 me!) is going to close it.
Please keep in mind that I鈥檓 only a robot, so if I鈥檝e closed this issue in error, I鈥檓 HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!
Thanks again for being part of the Gatsby community!