Angular 17 build fails

I have an Angular 17 app which I want to deploy.
It’s always throwing the same weird error and not mentioning anything specific other than “An unexpected error occurred: [object Object]”, but it mentions 2 different exit codes:

Failed during stage “building site”: Build script returned non-zero exit code: 2

and then

Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)

But it seems like something from the build of the netlify app.
What am I missing?
I already tried with and without the Angular runtime in the deploy settings, but it didn’t change a single thing while doing so.
In my local environment it builds perfectly fine even if I clone from scratch my repo, npm install and then npm run build.

Below the details:

Site name: storied-sprinkles-1b4534

Logs:

11:43:22 AM: build-image version: 3ffff9df3d5419545acc1b673a54de348174406d (focal)
11:43:22 AM: buildbot version: 06bd328e5eb3b6956f9c6602486ecccce8b861a0
11:43:22 AM: Building without cache
11:43:22 AM: Starting to prepare the repo for build
11:43:22 AM: No cached dependencies found. Cloning fresh repo
11:43:22 AM: git clone --filter=blob:none https://github.com/CesarD/decapng
11:43:22 AM: Preparing Git Reference refs/heads/master
11:43:24 AM: Starting to install dependencies
11:43:24 AM: Python version set to 3.8
11:43:24 AM: Attempting Ruby version 2.7.2, read from environment
11:43:25 AM: Using Ruby version 2.7.2
11:43:25 AM: Started restoring cached go cache
11:43:25 AM: Finished restoring cached go cache
11:43:26 AM: go version go1.19.13 linux/amd64
11:43:27 AM: Using PHP version 8.0
11:43:28 AM: Downloading and installing node v18.19.0…
11:43:28 AM: Downloading https://nodejs.org/dist/v18.19.0/node-v18.19.0-linux-x64.tar.xz
11:43:28 AM: Computing checksum with sha256sum
11:43:28 AM: Checksums matched!
11:43:30 AM: Now using node v18.19.0 (npm v10.2.3)
11:43:30 AM: Enabling Node.js Corepack
11:43:30 AM: Started restoring cached build plugins
11:43:30 AM: Finished restoring cached build plugins
11:43:30 AM: Started restoring cached corepack dependencies
11:43:30 AM: Finished restoring cached corepack dependencies
11:43:30 AM: No npm workspaces detected
11:43:30 AM: Started restoring cached node modules
11:43:30 AM: Finished restoring cached node modules
11:43:30 AM: Installing npm packages using npm version 10.2.3
11:43:41 AM: npm WARN deprecated abab@2.0.6: Use your platform"s native atob() and btoa() methods instead
11:43:41 AM: added 989 packages, and audited 990 packages in 10s
11:43:41 AM: 119 packages are looking for funding
11:43:41 AM: run npm fund for details
11:43:41 AM: 4 moderate severity vulnerabilities
11:43:41 AM: To address all issues (including breaking changes), run:
11:43:41 AM: npm audit fix --force
11:43:41 AM: Run npm audit for details.
11:43:41 AM: npm packages installed
11:43:42 AM: Successfully installed dependencies
11:43:42 AM: Starting build script
11:43:42 AM: Detected 1 framework(s)
11:43:42 AM: “angular” at version “17.0.6”
11:43:42 AM: Section completed: initializing
11:43:44 AM: ​
11:43:44 AM: Netlify Build
11:43:44 AM: ────────────────────────────────────────────────────────────────
11:43:44 AM: ​
11:43:44 AM: ❯ Version
11:43:44 AM: @netlify/build 29.31.0
11:43:44 AM: ​
11:43:44 AM: ❯ Flags
11:43:44 AM: baseRelDir: true
11:43:44 AM: buildId: 65783948cf0a0144087cfd23
11:43:44 AM: deployId: 65783948cf0a0144087cfd25
11:43:44 AM: ​
11:43:44 AM: ❯ Current directory
11:43:44 AM: /opt/build/repo
11:43:44 AM: ​
11:43:44 AM: ❯ Config file
11:43:44 AM: No config file was defined: using default values.
11:43:44 AM: ​
11:43:44 AM: ❯ Context
11:43:44 AM: production
11:43:44 AM: ​
11:43:44 AM: Build command from Netlify app
11:43:44 AM: ────────────────────────────────────────────────────────────────
11:43:44 AM: ​
11:43:44 AM: $ npm run build
11:43:44 AM: > decap-ng@0.0.0 build
11:43:44 AM: > ng build
11:43:45 AM: - Building…
11:43:55 AM: Failed during stage “building site”: Build script returned non-zero exit code: 2
11:43:54 AM: An unexpected error occurred: [object Object]
11:43:54 AM: ​
11:43:54 AM: “build.command” failed
11:43:54 AM: ────────────────────────────────────────────────────────────────
11:43:54 AM: ​
11:43:54 AM: Error message
11:43:54 AM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
11:43:54 AM: ​
11:43:54 AM: Error location
11:43:54 AM: In Build command from Netlify app:
11:43:54 AM: npm run build
11:43:54 AM: ​
11:43:54 AM: Resolved config
11:43:54 AM: build:
11:43:54 AM: command: npm run build
11:43:54 AM: commandOrigin: ui
11:43:54 AM: publish: /opt/build/repo/dist/decap-ng/browser
11:43:54 AM: publishOrigin: ui
11:43:55 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:43:55 AM: Failing build: Failed to build site
11:43:55 AM: Finished processing build request in 33.616s

Any help will be much appreciated. Thanks.

1 Like

Any help I can get on this?

This seems to be the issue and we don’t have any further insights than that. You might have to look for help among Angular devs on how to troubleshoot such an error which provides no info.

The thing is I cannot reproduce this locally, which means this is an environmental thing, thus I was hoping to find a way to better troubleshoot this from your environment… Perhaps there’s some configuration I can enable that provides better feedback/insights about what’s going on during the build phase on Netlify’s end?

This is just a plain Angular app that I just created and added Decap CMS on top of it by adding their scripts. There’s no other particular stuff added to it besides that. I highly doubt Angular team will be able to provide any feedback or troubleshooting if I can’t even reproduce it locally and there’s nothing signaling that Angular is the problem.

I’m not denying this being a Netlify issue, but I’m just saying that given this information, we can’t really check anything. At a minimum, we’d need some kind of an error message or description, to at least go look. But text like:

An unexpected error occured

doesn’t give us much to go on here.

The reason I asked you to try contacting Angular devs was to figure out how you can extract the error details here. I’m assuming the error is actually being passed to .toString() which is converting it to [object Object], but as you can imagine, we can’t get the error message back from that. Maybe, once you see the actual error message, you’d yourself figure out the issue, but without that, we can continue going on about this, but never reach a conclusion.

Netlify has a debug mode for logging, but that won’t change what gets logged by the framework. You can set NETLIFY_BUILD_DEBUG environment variable to true. Maybe Angular has something similar to increase verbosity? That’s the kind of information you can get from the Angular team. Not asking them “what’s wrong”, but asking them “what to look for”, could also help us check accordingly.

I had the same error with version 17.0.3 of Angular, i solved the problem by upgrading to the latest version 17.0.8.