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 Development\react> 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:\Users\James98\.swa\dataApiBuilder\0.7.5\Microsoft.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:\Users\James98\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\src\core\utils\command.ts:18:29)
at init (C:\Users\James98\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\src\cli\commands\db\init\init.ts:110:18)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at Command.<anonymous> (C:\Users\James98\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\src\cli\commands\db\init\register.ts:30:7)
at Command.parseAsync (C:\Users\James98\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\node_modules\commander\lib\command.js:935:5)
at run (C:\Users\James98\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\src\cli\index.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 Development\react> 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/dab_win-x64-0.7.5.zip@0.7.5
[dataApi] This version of C:\Users\James98\.swa\dataApiBuilder\0.7.5\Microsoft.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 Development\react\swa-db-connections" && "C:\Users\James98\.swa\dataApiBuilder\0.7.5\Microsoft.DataApiBuilder.exe" start -c staticwebapp.database.config.json --no-https-redirect exited with code 1
--> Sending SIGTERM to other processes..
[swa] node "C:\Users\James98\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\dist\msha\server.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:\Users\James98\.swa\dataApiBuilder.
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. Upgrade swa-cli to v1.1.4 or later. This version doesn't use unzipper
.
Option 2. Downgrade Node.js to v16.x or v18.15.0
Option 3. (Keep using Node 18.16.0) Extract c:\users\{account}\.swa\dataApiBuilder\%VERSION_OF_DAB%\dab_win-x64-%VERSION_OF_DAB%.zip
manually into c:\users\{account}\.swa\dataApiBuilder\%VERSION_OF_DAB%
You may need to delete the folder or, at least, the contents of the folder at %USERPROFILE%\.swa\dataApiBuilder\
so any invalid files can be replaced by valid files.