skip to Main Content

I am attempting to use SWA-CLI to run/debug a react web app in a PowerShell terminal in Visual Studio Code on my Windows PC. My setup is:

OS: Windows 10 Pro (10.0.19044 Build 19044)
VS Code: 1.78.2
PowerShell: 5.1.19041.2673
SWA-CLI: 1.1.2
Node.js: 18.160.0
npm: 9.6.6

Problems first showed up when trying to initialize my project for database access:

PS C:Local Developmentreact> swa db init --database-type mssql

Welcome to Azure Static Web Apps CLI (1.1.2)

[swa] Creating database connections configuration folder swa-db-connections
[swa] Creating staticwebapp.database.config.json configuration file
node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^

<ref *1> Error: spawnSync C:UsersJames98.swadataApiBuilder.7.5Microsoft.DataApiBuilder.exe UNKNOWN
    at Object.spawnSync (node:internal/child_process:1110:20)
    at spawnSync (node:child_process:871:24)
    at execFileSync (node:child_process:914:15)
    at execFileCommand (C:UsersJames98AppDataRoamingnpmnode_modules@azurestatic-web-apps-clisrccoreutilscommand.ts:18:29)
    at init (C:UsersJames98AppDataRoamingnpmnode_modules@azurestatic-web-apps-clisrcclicommandsdbinitinit.ts:110:18)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Command.<anonymous> (C:UsersJames98AppDataRoamingnpmnode_modules@azurestatic-web-apps-clisrcclicommandsdbinitregister.ts:30:7)
    at Command.parseAsync (C:UsersJames98AppDataRoamingnpmnode_modules@azurestatic-web-apps-clinode_modulescommanderlibcommand.js:935:5)
    at run (C:UsersJames98AppDataRoamingnpmnode_modules@azurestatic-web-apps-clisrccliindex.ts:106:3) {  
  errno: -4094,
  code: 'UNKNOWN',
  syscall: 'spawnSync C:\Users\James98\.swa\dataApiBuilder\0.7.5\Microsoft.DataApiBuilder.exe',
  path: 'C:\Users\James98\.swa\dataApiBuilder\0.7.5\Microsoft.DataApiBuilder.exe',
  spawnargs: [
    'init',
    '--database-type',
    'mssql',
    '--config',
    'staticwebapp.database.config.json',
    '--rest.path',
    '/rest'
  ],
  error: [Circular *1],
  status: null,
  signal: null,
  output: null,
  pid: 0,
  stdout: null,
  stderr: null
}

I managed to work around the above error by creating a swa-db-connections folder and creating my own staticwebapp.database.config.json file (incidentally, when the project is uploaded to my StaticWebApp on Azure, the database connection works GREAT!).

The problem that I can’t seem to get around, however, is simulating the project locally. I start the local development server separately because swa doesn’t seem to be able to detect when it is up-and-running, but when I try to get swa to manage the database connections, I receive a message saying that Microsoft.DataApiBuilder is not compatible with my Windows version?

PS C:Local Developmentreact> swa start http://localhost:3000 --data-api-location ./swa-db-connections

Welcome to Azure Static Web Apps CLI (1.1.2)

***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure.                           *
***********************************************************************

[swa] ✔ Downloading https://github.com/Azure/data-api-builder/releases/download/v0.7.5/[email protected]
[dataApi] This version of C:UsersJames98.swadataApiBuilder.7.5Microsoft.DataApiBuilder.exe is not compatible 
with the version of Windows you're running. Check your computer's system information and then contact the software publisher.
[dataApi] cd "C:Local Developmentreactswa-db-connections" && "C:UsersJames98.swadataApiBuilder.7.5Microsoft.DataApiBuilder.exe" start -c staticwebapp.database.config.json --no-https-redirect exited with code 1
--> Sending SIGTERM to other processes..
[swa] node "C:UsersJames98AppDataRoamingnpmnode_modules@azurestatic-web-apps-clidistmshaserver.js" exited with code 1
✖ SWA emulator stoped because SWA emulator exited with code 1.

I am not sure where to even start troubleshooting since I am running up-to-date versions of Windows, SWA-CLI, Node and npm…If anyone has any suggestions of what to try next, I would GREATLY appreciate them!

When I first encountered the error, I updated my toolset(s). I don’t know what version each tool was when I started. But I am getting the same behavior with the updated tools that are listed at the top.

Once doing that, I have tried uninstalling/reinstalling swa multiple times using:

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

I have also tried deleting the folder at C:UsersJames98.swadataApiBuilder.

2

Answers


  1. I encountered a similar error, and I was able to resolve it by downgrading my Node.js version from 18 to 16. After the downgrade, the swa command worked successfully.

    Login or Signup to reply.
  2. Looks like This is a issue of unzipper which is used for extracting the zip file of DataApiBuilder. It cannot work properly on Node v18.16.0.
    As a result, the extracted files are broken.

    There are some options to resolve this issue.

    Option 1. Downgrade Node.js to v16.x or v18.15.0
    Option 2. Extract %USERPROFILE%.swadataApiBuilder%VERSION_OF_DAB%dab_win-x64-%VERSION_OF_DAB%.zip manually

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search