top of page

Debugging Azure Static Web Apps Command Line Interface (SWA CLI)

Sometimes, deploying Azure Static Web Apps via the CLI (SWA CLI) fails with unhelpful errors or no errors at all. This post describes how I modified the SWA CLI to improve logging and ultimately diagnose a silent deployment failure.

The Problem

In my case, I created a sample Static Web App with a home.html file instead of the expected index.html. As a result, deployments failed silently when running the following command:

swa deploy src --env production

No errors were displayed, and the deployment failed without explanation.

Capturing SWA Deployment Logs

To investigate further, I redirected the output of the deploy command to a log file:

swa deploy src --env production silly > deployment-log.txt 2>&1

Unfortunately, the log file contained no helpful information. After reviewing the Azure SWA CLI, it was discovered that errors were being swallowed or sanitised.

Modifying the SWA CLI for Better Logging

To expose the missing error output, the SWA CLI source code can be modified to log all errors during deployment.

Step 1: Locate the Installed Package

First, determine where npm has installed the packages by running one of the following commands:

npm root
npm root -g

Then open the deploy.js file:

<npm root -g>\@azure\static-web-apps-cli\dist\cli\commands\deploy\deploy.js.

My full path to the deploy.js:

C:\nvm4w\nodejs\node_modules\@azure\static-web-apps-cli\dist\cli\commands\deploy. 

NOTE - Your path may differ depending on your Node.js and npm setup.

Step 2: Add Logging to the Deploy Command

Locate the following code (around line 234):

child.stdout.on("data", (data) => {
data
	.toString()
	.trim()
	.split("\n")
	.forEach((line) => {

Insert the following line immediately after the opening brace:

console.log('stderr: ' + data);

The updated code should look like this:

child.stdout.on("data", (data) => {
console.log('stderr: ' + data);
data
	.toString()
	.trim()
	.split("\n")
	.forEach((line) => {

The Result

After making the above change, I ran the swa deploy command again.

swa deploy src --env <env>--deployment-token <deployment token> silly > deployment-log.txt 2>&1

This time, the log file contained a meaningful error message:

stderr: Failed to find a default file in the app artifacts folder (\src). Valid default files: index.html,Index.html.

If your application contains purely static content, please verify that the variable 'app_location' in your deployment configuration file points to the root of your application.

If your application requires build steps, please validate that a default file exists in the build output directory.

Recent Posts

See All

Comments


bottom of page