最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - How to resolve Node Error when deploying azure static web app with the statice web app CLI - Stack Overflow

programmeradmin3浏览0评论

I am executing the Static Web API CLI to deploy a simple HTML website.

swa deploy --api-language none --api-version none --env Production --verbose > deployment-log.txt 2>&1

The output is

Welcome to Azure Static Web Apps CLI (2.0.3)

Using configuration "static-web-apps-play-ground" from file:
  C:\Users\####\source\repos\StaticWebApps-PlayGround\swa-cli.config.json

Deploying front-end files from folder:
  C:\Users\####\source\repos\StaticWebApps-PlayGround\src


Deploying to environment: Production

Deploying project to Azure Static Web Apps...
node.exe : - Preparing deployment. Please wait...
At C:\nvm4w\nodejs\swa.ps1:16 char:5
+     & "$basedir/node$exe"  "$basedir/node_modules/@azure/static-web-a ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (- Preparing deployment. Please wait...:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

The swa-cli-config.json is

{
  "$schema": ";,
  "configurations": {
    "static-web-apps-play-ground": {
      "appLocation": "./src/",
      "appName": "swa-playground",
      "resourceGroup": "rg-swa-playground"
    }
  }
}

Node version is 20.18.3, but I have also tried it with versions 18.17.1 and 16.20.2 SWA version is 2.03

I am executing the Static Web API CLI to deploy a simple HTML website.

swa deploy --api-language none --api-version none --env Production --verbose > deployment-log.txt 2>&1

The output is

Welcome to Azure Static Web Apps CLI (2.0.3)

Using configuration "static-web-apps-play-ground" from file:
  C:\Users\####\source\repos\StaticWebApps-PlayGround\swa-cli.config.json

Deploying front-end files from folder:
  C:\Users\####\source\repos\StaticWebApps-PlayGround\src


Deploying to environment: Production

Deploying project to Azure Static Web Apps...
node.exe : - Preparing deployment. Please wait...
At C:\nvm4w\nodejs\swa.ps1:16 char:5
+     & "$basedir/node$exe"  "$basedir/node_modules/@azure/static-web-a ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (- Preparing deployment. Please wait...:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

The swa-cli-config.json is

{
  "$schema": "https://aka.ms/azure/static-web-apps-cli/schema",
  "configurations": {
    "static-web-apps-play-ground": {
      "appLocation": "./src/",
      "appName": "swa-playground",
      "resourceGroup": "rg-swa-playground"
    }
  }
}

Node version is 20.18.3, but I have also tried it with versions 18.17.1 and 16.20.2 SWA version is 2.03

Share Improve this question asked Feb 16 at 5:29 user3845056user3845056 49710 silver badges29 bronze badges 2
  • According to the documentation, Node.js versions 12, 14, 16, and 18 are supported. Since you're using Node.js 20, this might be causing the issue. Try downgrading to one of the supported versions (e.g., Node.js 18). – Sampath Commented Feb 16 at 8:48
  • I have tried it with NodeJs 18 and 16, using nvm use 18 and nvm use 16. Is this the correct way to downgrade? – user3845056 Commented Feb 16 at 14:46
Add a comment  | 

2 Answers 2

Reset to default 0

I tried using Node 20 and encountered the same issue. However, it worked fine with Node v18.20.2. Uninstall Node 20 and try downgrading to one of the supported versions (e.g., Node 18). For more details, refer to this GitHub issue and MSDOC

As mentioned in this MSDOC, APIs in Azure Static Web Apps must be implemented using Azure Functions or external API services such as Azure API Management, App Service, or Container Apps. Based on my understanding, a sample HTML file serves as the front-end web application.

To install the Azure Static Web Apps CLI, use the following command:

npm install -g @azure/static-web-apps-cli

Then, initialize the CLI by running:

swa init -y

This sets up the Azure Static Web Apps CLI.

To authenticate with Azure Static Web Apps using your Azure account, use:

swa login

Once authenticated, retry the deployment with:

swa deploy ./src

If your project includes an API, use: swa deploy ./src --api-location ./api

Output:

I modified the swa cli js files to include extra logging and found the root cause was because I did not have an index.html file, I only had a home.html file.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论