Netlify: How do you deploy sites that are nested in a folder?
Asked Answered
R

2

12

I have a repo that has the backend and frontend (create-react-app) in two separate folders. For the build command, I have something like cd frontend && npm run build and for the publish directory, I have something like frontend/build, but this is not working.

Redhead answered 16/5, 2018 at 7:37 Comment(4)
@Michael L. do you get an error in the deploy?Onfre
12:32:20 AM: Error running command: Build script returned non-zero exit code: 1 12:32:21 AM: Failing build: Failed to build site 12:32:20 AM: failed during stage 'building site': Build script returned non-zero exit code: 1Redhead
If you run it local, you should get the same error if you run the same command. look at the originating error for the reason for the failure.Onfre
running cd frontend && npm run build locally worksRedhead
P
24

disclaimer: I work for Netlify.

If you were to clone a new copy (no node modules installed in the project, for instance) of your project on a fresh laptop with nothing else except node and npm installed there, how would you build it? Imagine netlify's build process like that. So you're missing at least an "npm install" step in there :)

Anything else missing, like globally installed npm packages? Need to specify them in package.json so that Netlify's build network knows to grab them for you. Ruby gems? Better have a Gemfile in your repo!

Netlify tries to npm install (and bundle install) automatically for you, assuming there is a package.json either in the root of your repository (I'm guessing yours is in frontend/ ?) OR if you set the "base" parameter so that we start our build in the base directory. This is probably a good pattern for you, to set "base" to frontend, and then set your publish directory to build.

You can specify that base parameter in netlify.toml something like this:

[build] base = "frontend"

Note that netlify.toml must reside in the root of your repository.

For more details on how Netlify builds, check out the following articles:

If after some reading and experimenting, you still can't figure things out, ping the helpdesk.

Philippic answered 16/5, 2018 at 13:32 Comment(4)
My other sites that were made with create-react-app and are not nested in a frontend/backend folder do not have an npm install command and they work fine. Where do I change the install command?Redhead
@MichaelL. As I mentioned you either set the base in netlify.toml and then you don't need npm install since that happens automatically, or you change the command near the top of build & deploy settings in the UI for that site. Setting a base is recommended!Philippic
Eureka! Interestingly, my build command was relative to my base directory like "npm run build", but my publish directory was relative to the root of my repository "frontend/build".Redhead
This should be in the last link you provided too.. or at least, a link to this question ;)Kanarese
N
0

The top answer is correct ^. For anyone looking to simply change the base directory (lets say there is only one npm install/start) you need to change the BASE DIRECTORY, which you will find in the build settings. Simply go to: site-settings -> build & deploy - and you will see it where I pointed in the picture attacted. Hopefully that helps someone in need of this.

screenshot of netlify

Nonparticipation answered 14/5, 2022 at 0:57 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.