Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a Gatsby app as a package within a monorepo works #9352

Closed
jedrichards opened this issue Oct 24, 2018 · 13 comments
Closed

Using a Gatsby app as a package within a monorepo works #9352

jedrichards opened this issue Oct 24, 2018 · 13 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more. type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@jedrichards
Copy link
Contributor

jedrichards commented Oct 24, 2018

Summary

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

Relevant information

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.

Environment

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
@kakadiadarpan kakadiadarpan added status: inkteam to review type: question or discussion Issue discussing or asking a question about Gatsby labels Nov 14, 2018
@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Feb 1, 2019
@gatsbot
Copy link

gatsbot bot commented Feb 1, 2019

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’s 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! 💪💜

@jedrichards
Copy link
Contributor Author

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.

@gatsbot
Copy link

gatsbot bot commented Feb 14, 2019

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.

Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m 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!

@gatsbot gatsbot bot closed this as completed Feb 14, 2019
@johntran
Copy link

I'm evaluating Gatsby in a monorepo environment. I found this issue through a Google search. Thank you for doing a writeup on it :).

@johntran
Copy link

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/

@jedrichards
Copy link
Contributor Author

@johntran Oh interesting, ty for the blog link! 👀

@m-allanson m-allanson added not stale and removed stale? Issue that may be closed soon due to the original author not responding any more. labels Feb 15, 2019
@m-allanson m-allanson reopened this Feb 15, 2019
@josefaidt
Copy link
Contributor

josefaidt commented Feb 15, 2019

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

@jedrichards
Copy link
Contributor Author

jedrichards commented Feb 15, 2019

@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

@josefaidt
Copy link
Contributor

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.

@josefaidt
Copy link
Contributor

josefaidt commented Feb 15, 2019

@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 😬

@jedrichards
Copy link
Contributor Author

jedrichards commented Feb 15, 2019

@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.

@gatsbot
Copy link

gatsbot bot commented Aug 3, 2019

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’s 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! 💪💜

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Aug 3, 2019
@gatsbot
Copy link

gatsbot bot commented Aug 14, 2019

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.

Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m 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!

@gatsbot gatsbot bot closed this as completed Aug 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more. type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

6 participants