Deploy Failed during stage 'building site1

PLEASE help us help you by writing a good post!

I’m trying to publish https://darty-ai-docs.netlify.app/
It’s stored on GitHub, I’ve installed the Netlify app to the repo and linked my Netlify and Github users successfully.

The scripts I have available in my package.json are

"scripts": {
    "dev": "vuepress dev src",
    "build": "vuepress build src",
  },

My deploy config is

Base directory: docs
Build command: yarn build
Publish directory: docs/.vuepress/dist

When I manually build I cd to docs from the root of my repo (The root is the one that shows up on GitHub)
cd docs
Then I can run yarn build and it builds.
I can’t run yarn build from the root.

My folder structure is as in the screenshot.

The deployment is failing on Netlify, please can you help me to get it to work?
I suspect the deploy config is not correct.

Unfortunately, the logs are not working
2:14:12 AM: [ERROR] Deploy logs are currently unavailable. We are working on resolving the issue.

The error messages are

Production: master@HEAD Failed
Failed during stage 'building site1: Build script returned non-zero exit code: 2

Thank you

Hi @Trevor1,

Thanks for reaching out and welcome to Netlify’s Support Forums!

Looking at the deploy log, I’m seeing this error:

7:14:37 PM: Error: error:0308010C:digital envelope routines::unsupported
7:14:37 PM:     at new Hash (node:internal/crypto/hash:71:19)
7:14:37 PM:     at Object.createHash (node:crypto:133:10)
7:14:37 PM:     at module.exports (/opt/build/repo/docs/node_modules/webpack/lib/util/createHash.js:135:53)
7:14:37 PM:     at NormalModule._initBuildHash (/opt/build/repo/docs/node_modules/webpack/lib/NormalModule.js:417:16)
7:14:37 PM:     at handleParseError (/opt/build/repo/docs/node_modules/webpack/lib/NormalModule.js:471:10)
7:14:37 PM:     at /opt/build/repo/docs/node_modules/webpack/lib/NormalModule.js:503:5
7:14:37 PM:     at /opt/build/repo/docs/node_modules/webpack/lib/NormalModule.js:358:12
7:14:37 PM:     at /opt/build/repo/docs/node_modules/loader-runner/lib/LoaderRunner.js:373:3
7:14:37 PM:     at iterateNormalLoaders (/opt/build/repo/docs/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
7:14:37 PM:     at iterateNormalLoaders (/opt/build/repo/docs/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
7:14:37 PM:     at /opt/build/repo/docs/node_modules/loader-runner/lib/LoaderRunner.js:236:3
7:14:37 PM:     at context.callback (/opt/build/repo/docs/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
7:14:37 PM:     at /opt/build/repo/docs/node_modules/cache-loader/dist/index.js:134:7
7:14:37 PM:     at /opt/build/repo/docs/node_modules/graceful-fs/graceful-fs.js:61:14
7:14:37 PM:     at FSReqCallback.oncomplete (node:fs:198:23) {
7:14:37 PM:   opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
7:14:37 PM:   library: 'digital envelope routines',
7:14:37 PM:   reason: 'unsupported',
7:14:37 PM:   code: 'ERR_OSSL_EVP_UNSUPPORTED'
7:14:37 PM: }

There is a StackOverflow post about this here:

I’m assuming that the dependency install and build works locally. If so, we recommend configuring the build dependencies at Netlify to as closely match your local build environment as possible.

1 Like

Thank you, Melvin.
That looks very promising. I will get back with the results.

I set the node environment to the one I used on my local system.
That helped a bit. I have moved on to other errors now.

7:48:18 PM: [success] [webpackbar] Client: Compiled successfully in 7.71s
7:48:18 PM: wait Rendering static HTML...
7:48:18 PM: success Generated static files in src/.vuepress/dist.
7:48:18 PM: Done in 9.10s.
7:48:18 PM: ​
7:48:18 PM: (build.command completed in 9.2s)
7:48:18 PM: Build step duration: build.command completed in 9290ms
7:48:18 PM: ​
7:48:21 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
7:48:21 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:48:21 PM: Failing build: Failed to build site
7:48:22 PM: Finished processing build request in 37.49s

I set NETLIFY_BUILD_DEBUG to TRUE and changed my yarn command on package.json and the Netlify config from yarn build to yarn docs:build following advice from [Support Guide] Frequently encountered problems during builds but I can’t get it to build without an error.

My package.json contents (email changed) is:

{
  "name": "darty-docs",
  "version": "0.0.1",
  "description": "Documentation for Darty Ai",
  "main": "index.js",
  "authors": {
    "name": "Trevor",
    "email": "*****@******.com"
  },
  "repository": "/Darty-Docs",
  "scripts": {
    "dev": "vuepress dev src",
    "docs:build": "vuepress build src",
    "b": "vuepress build src",
    "bd": "vuepress build src && vuepress dev src",
    "index": "node -e \"require('../build-code/test-script.js').default()\""
  },
  "license": "MIT",
  "devDependencies": {
    "vuepress": "^1.5.3",
    "vuepress-plugin-fulltext-search": "^2.2.1"
  },
  "dependencies": {
    "@vuepress/plugin-back-to-top": "^1.9.9",
    "@vuepress/plugin-medium-zoom": "^1.9.9"
  }
}

The build is Netlify App

Please can you give me some more guidance?

Things are moving a bit.
I have added a folder /docs/.vuepress/dist and now it builds.
The problem is I am getting


My folder structure now looks like

@Trevor1 Based on your screenshot, the only thing I know for certain that the /docs/.vuepress/dist folder contains is a file called place-holder.txt

I’m guessing you have your Publish directory set to /docs/.vuepress/dist as I can see that file here:
https://darty-ai-docs.netlify.app/place-holder.txt

If that is what you’re deploying, then you should run your build locally and make sure the correct files, including an index.html are ending up in /docs/.vuepress/dist

Thanks!
I linked the deploy location to the correct path.
I understand now that the Vuepress site needs to be built locally first with the dist pushed to the GitHub record. I had presumed that the build process on Netlify would create the dist folder when it ran the build command, but this seems wrong.

If I need to include the ready-made dist folder with the static HTML files, can I not just include those files and not do a build command or include any other files in the repo?

What you’ve done is certainly one way to get the files live, however it is wrong if you “want to build on Netlify”.

It should be a case of ensuring that your Basic build settings are configured to do what you want.

E.g. Navigating to the right Base directory, running the right Build command and specifying the right Publish directory

You’re also correct in that, if you were “building locally”, there would be no need to push any source files at all to Netlify, you could push only the output.

1 Like

Ok, I think all is clear for now.

I have two ways to publish my Vuepress site on Netlify.

  1. To build locally to the “Publish Directory” path set in Netlify’s build config and leave the configs “Build Command” blank. This method should be pretty safe as I shouldn’t need to worry about the Netlify environment and the build failing on Netlify. This is the method I’m using for now as it’s the one that I can get to work!

  2. Not to build locally, but rather use Netlify to build for me, I need to worry about Netlify’s environment and whether Netlify will build successfully. I need to include the correct Build Command, but shouldn’t push the publish folder because Netlify should create that for me.

Can you confirm that these are two ways to go? It sounds very much so from your above answer.

Presuming that method 2 (build on Netlify) is valid, besides the lack of need to build locally what would be the most significant one or two advantages of getting Netlify to do the build?

@Trevor1 There are other ways, for example you could run your build locally and then only commit the output to a repository that only contains the output, or to use the Netlify CLI to do the deploy the output files.

The main advantage to having a build run on Netlify comes when you want new builds/deployments to be able to occur separately from code pushes, for example when site content is being edited via some other means, or triggering on a cron etc.

You may be being overly fearful of getting the Netlify environment “correct”.

If I’m interpreting your folder structure screenshot correctly, it should just be:
Base directory docs
Build command npm run build
Deploy directory docs/.vuepress/.dist

The .nvmrc in docs would switch Netlify to use that version of node.
The package.json in docs would automatically have its dependencies installed.
The package.json in docs would end up having its build script executed.
The files in docs/.vuepress/.dist would be all that gets deployed to the CDN.