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.

- 5,052
- 9
- 42
- 75
-
[@Michael L.](https://stackoverflow.com/users/4975090/michael-l) do you get an error in the deploy? – talves May 16 '18 at 18:46
-
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: 1 – sdfsdf May 16 '18 at 19:27
-
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. – talves May 16 '18 at 22:12
-
running `cd frontend && npm run build` locally works – sdfsdf May 16 '18 at 22:18
2 Answers
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:
- Overview of how our build network works. This article also shows how you can download our build image to test locally.
- Settings that affect our build environment. Useful for telling us about what node version to use, for instance.
- Some frequently experienced problems
If after some reading and experimenting, you still can't figure things out, ping the helpdesk.

- 3,044
- 20
- 28
-
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? – sdfsdf May 16 '18 at 19:25
-
@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! – fool May 17 '18 at 22:25
-
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". – sdfsdf May 20 '18 at 17:43
-
This should be in the last link you provided too.. or at least, a link to this question ;) – gbianchi May 22 '18 at 05:01
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.
]

- 10,231
- 7
- 64
- 116

- 35
- 5