Getting Next.js to see shared code in Yarn Monorepo?August 8, 2018 at 11:10pm
I am currently unable to get my Next.js application inside of my Yarn monorepo to see shared code. Is there any steps I should be taking, such as my config, to get everything linked up? Thanks a ton for your time.
August 9, 2018 at 7:35am
August 9, 2018 at 6:02pm
Thanks for the replies! I'm actually starting several Next.js apps from scratch concurrently. I have these each as their own package. I also have another package that is going to be a React component library. I have been able to properly hook up the component library to
create-react-appprojects just from Googling, but am at a loss on how to wire Next.js apps.
Monorepo structure might look something like:
I'm largely doing something like this: https://medium.com/viewstools/how-to-use-yarn-workspaces-with-create-react-app-and-create-react-native-app-expo-to-share-common-ea27bc4bad62
But instead of CRA/CRNA, I was hoping to have a Next.js project that can also share components with other applications.
August 10, 2018 at 7:23am
You can use this plugin! https://github.com/wellcometrust/next-plugin-transpile-modules
I'm using it in a monorepo structure, and it's matches the structure you provided above, and it did works!
Let me know if it does work for you too :)
Which Next version it was? Since v5 with plugins it's less bit of a pain :)
August 14, 2018 at 12:55pm
December 17, 2018 at 11:17pm
December 18, 2018 at 9:43am
Hey all, since Next uses a newer version of babel, the root level `.babelrc` no longer works. Instead, you need to add a root level `babel.config.js` file and use a next.js plugin to have next's babel-loader resolve the shared config file:
Let me know how you get on and if I can help at all.
December 18, 2018 at 7:23pm
December 23, 2018 at 11:41am
December 24, 2018 at 10:11am
December 29, 2018 at 6:38pm
As promised, I've written a blog post explaining how to set up a Next.js monorepo with TypeScript and custom Babel config:
If you prefer to see some code, I've also set up an example repo here:
February 15, 2019 at 3:38pm
Thank you for the post. It is awesome! I wonder how the deployment will look like with the monorepo setup. For instance, if one follows this post (https://medium.com/deploy-a-next-js-app-on-heroku-69bcb01db1b7) and wants to deploy next.js app on heroku. What should steps look like?
I haven't had time to write a post explaining the steps, but I recently converted a full-stack monorepo typescript app to serverless (deployed to AWS lambda via serverless)
The repo is here:
I've been too busy with work to put together the post, but when I do, I'll be sure to update this thread!
February 16, 2019 at 2:09am
thanks again. I have tried to deploy next.js with zeit now v2. It now comes with the serverless option, but could not make it work. Any pages with the dynamic content do not server-side render. Have you tried zeit now? Can you please take a look at this issue? https://github.com/zeit/now-cli/issues/1889
March 5, 2019 at 4:15pm
That repo you created is going to be super helpful for me. Thanks so much for posting it. A quick question: I see from your package.json that you're using slate for documenting your api. It looks cool, but I'm assuming there's a Ruby dependency?
Also, I see the nohoist flag inside your yarn workspace's package.json. What's the specific use case that's requiring that? I know the option keeps some packages inside the local sub-package's node_modules folder, but which functionality are you enabling with this?
Is it related to the withTranspile(...[""]...) call that you make later?