question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

swa 1.0.3 with Node18 - Can't reach api endpoint

See original GitHub issue

Describe the bug The last version of the swa cli (1.0.3) doesn’t seem to work with NodeJS LTS 18.12.1 on a Blazor WASM with dotnet functions. The swa cli can’t connect to the api endpoint, but it works outside the swa cli either by running it via swa start or func host start:

[swa] ✖ Could not connect to “http://localhost:7071/”. Is the server up and running?

To Reproduce

> swa start http://localhost:5000 --run "dotnet watch run --project src/Client/Client.csproj" --api-location src/Api -V silly

Welcome to Azure Static Web Apps CLI (1.0.3)

Getting config file options from swa-cli.config.json...
Config file does not exist at <*****>\swa-cli.config.json
***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure.                           *
***********************************************************************

Checking if localhost:4280 is accepting TCP connections...
Port 4280 is available. Use it.
Resolved port number: 4280
appDevserverUrl provided, we will try connect to dev server at .
Trying to read workflow config with values:
 - appLocation: <*****>
 - outputLocation: http://localhost:5000
 - apiLocation: <*****>\src\Api
No workflow config folder found at <*****>\.github\workflows
Validating user workflow config (BEFORE):
 - appLocation: <*****>
 - outputLocation: http://localhost:5000
 - apiLocation: <*****>\src\Api
Validating user workflow config (AFTER):
 - appLocation: <*****>
 - apiLocation: <*****>\src\Api
 - outputLocation: http://localhost:5000
User workflow config:
 - appLocation: <*****>
 - apiLocation: <*****>\src\Api
 - outputLocation: http://localhost:5000
Starting the SWA emulator with the following configuration:
- ssl:
  - 0: false
  - 1: <undefined>
  - 2: <undefined>
- env:
  - SWA_RUNTIME_CONFIG_LOCATION: <*****>
  - SWA_RUNTIME_WORKFLOW_LOCATION: <undefined>
  - SWA_CLI_DEBUG: silly
  - SWA_CLI_API_PORT: 7071
  - SWA_CLI_APP_LOCATION: <*****>
  - SWA_CLI_OUTPUT_LOCATION: http://localhost:5000
  - SWA_CLI_API_LOCATION: <*****>\src\Api
  - SWA_CLI_HOST: localhost
  - SWA_CLI_PORT: 4280
  - SWA_CLI_APP_SSL: false
  - SWA_CLI_APP_SSL_CERT: <undefined>
  - SWA_CLI_APP_SSL_KEY: <undefined>
  - SWA_CLI_STARTUP_COMMAND: dotnet watch run --project src/Client/Client.csproj
  - SWA_CLI_VERSION: 1.0.3
  - SWA_CLI_SERVER_TIMEOUT: 60
  - SWA_CLI_OPEN_BROWSER: false
- commands:
  - swa: node "<*****>\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\dist\msha\server.js"
  - api: cd "<*****>\src\Api" && func start --cors "*" --port 7071 
  - run: cd "<*****>" && dotnet watch run --project src/Client/Client.csproj
[run] dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload. 
[run]   💡 Press "Ctrl + R" to restart.
[run] dotnet watch 🔧 Building...
[api] MSBuild version 17.3.2+561848881 for .NET
[api]   Determining projects to restore...
[run]   Determining projects to restore...
[swa] Loading staticwebapp.config.json schema...
[api]   All projects are up-to-date for restore.
[run]   All projects are up-to-date for restore.
[api]   Shared -> <*****>\src\Api\bin\output\Shared.dll
[run]   Shared -> <*****>\src\Shared\bin\Debug\net6.0\Shared.dll
[swa] Schema loaded successfully from https://json.schemastore.org/staticwebapp.config.json
[swa] Compiling schema...
[swa] Reading content from staticwebapp.config.json...
[swa] Parsing staticwebapp.config.json...
[swa] Validating staticwebapp.config.json...
[swa] File validated successfully. Continuing with configuration!
[swa] Content parsed successfully
[swa]
[swa] Found configuration file:
[swa]   <*****>\src\Client\wwwroot\staticwebapp.config.json
[swa]
[swa] Validating dev server config:
[swa]  - url: http://localhost:5000
[swa]  - timeout: 60
[swa] Checking if localhost:5000 is accepting TCP connections...
[swa] - Waiting for http://localhost:5000 to be ready
[api]   Api -> <*****>\src\Api\bin\output\Api.dll
[run]   Client -> <*****>\src\Client\bin\Debug\net6.0\Client.dll
[run]   Client (Blazor output) -> <*****>\src\Client\bin\Debug\net6.0\wwwroot
[api]   Determining projects to restore...
[api]   Restored <*****>\AppData\Local\Temp\rshjuuph.lof\WorkerExtensions.csproj (in 1 sec).
[run] dotnet watch 🚀 Started
[api]   WorkerExtensions -> <*****>\AppData\Local\Temp\rshjuuph.lof\buildout\Microsoft.Azure.Functions.Worker.Extensions.dll
[run] info: Microsoft.Hosting.Lifetime[14]
[run]       Now listening on: http://localhost:5000
[run] info: Microsoft.Hosting.Lifetime[0]
[run]       Application started. Press Ctrl+C to shut down.
[swa] ✔ Connected to http://localhost:5000 successfully
[run] infoValidating dev server config:
[run] : Microsoft.Hosting.Lifetime[0]
[run]       Hosting environment: Development
[run] info: Microsoft.Hosting.Lifetime[0]
[run]       Content root path: <*****>\src\Client
[swa]  - url: http://localhost:7071
[swa]  - timeout: 60
[swa] Checking if localhost:7071 is accepting TCP connections...
[swa] - Waiting for http://localhost:7071 to be ready
[api]
[api] Build succeeded.
[api]     0 Warning(s)
[api]     0 Error(s)
[api]
[api] Time Elapsed 00:00:07.15
[api]
[api]
[api]
[api] Azure Functions Core Tools
[api] Core Tools Version:       4.0.4865 Commit hash: N/A  (64-bit)
[api] Function Runtime Version: 4.12.2.19454
[api]
[api] [2022-11-08T11:47:39.657Z] Found <*****>\src\Api\Api.csproj. Using for user secrets file configuration.
[api]
[api] Functions:
[api]
[api]   <*****>: [GET] http://localhost:7071/api/<*****>/{culture}/{productItemKey}
[api]
[api]   <*****>: [GET] http://localhost:7071/api/<*****>/{subscriptionTicketKey}
[api]
[api]   Liveness: [GET] http://localhost:7071/api/Liveness
[api]
[api]   <*****>: [PUT] http://localhost:7071/api/<*****>
[api]
[api] For detailed output, run func with --verbose flag.
[api] [2022-11-08T11:47:42.497Z] Worker process started and initialized.
[api] [2022-11-08T11:47:46.312Z] Host lock lease acquired by instance ID '000000000000000000000000D3D4745D'.
[swa] ✖ Waiting for http://localhost:7071 to be ready
[swa] **✖ Could not connect to "http://localhost:7071". Is the server up and running?**
[swa] killing SWA CLI
[swa] node "<****>\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\dist\msha\server.js" exited with code 0
--> Sending SIGTERM to other processes..
[run] cd "<****>" && dotnet watch run --project src/Client/Client.csproj exited with code 1
--> Sending SIGTERM to other processes..
[api] cd "<****>\src\Api" && func start --cors "*" --port 7071  exited with code 1
**✖ SWA emulator stoped because API server exited with code 1.**

image

Desktop (please complete the following information):

  • OS: Windows 10
  • swa cli Version 1.0.3
  • NodeJs Version: LTS 18.12.1
  • Azure Functions Core Tools Version: 4.0.4865

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:4
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
sgollapudi77commented, Nov 16, 2022

Hey @arobthearab , @jouz3 we’re able to reproduce the same issue locally. Seems like something is breaking with azure function core tools v4 with Node18 installed. We’re investigating this issue and will get back to you soon. Meanwhile please try to downgrade the version of Node 16. Please feel free to contribute if anyone has any discoveries. Thanks.

0reactions
nathantccommented, Dec 12, 2022

I was receiving the same could not connect message and discovered it was simply my host file not routing localhost.

I learned that swa uses the ‘wait-on’ library to check for the host. Maybe logging the error response from ‘wait-on’ is needed. I executed the wait on using npx:

npx wait-on -v http://localhost:3000

I received the following:

making HTTP(S) head request to  url:http://localhost:3000 ...
  HTTP(S) error for http://localhost:3000 Error: connect ECONNREFUSED ::1:3000

Hope this helps!

My original error message:

[run] webpack compiled successfully
[run] Compiling...
[run] Compiled successfully!
[run] webpack compiled successfully
[swa] × Waiting for http://localhost:7071 to be ready
[swa] ✖ Could not connect to "http://localhost:7071". Is the server up and running?
[swa] node "C:\dev\node\node-v18.12.1-win-x64\node_modules\@azure\static-web-apps-cli\dist\msha\server.js" exited with code 0
--> Sending SIGTERM to other processes..
[run] cd "C:\dev\learning\vaesen-rpg" && npm start exited with code 1
--> Sending SIGTERM to other processes..
[api] cd "C:\dev\learning\vaesen-rpg\api" && func start --cors "*" --port 7071  exited with code 1
✖ SWA emulator stoped because API server exited with code 1.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't reach Node JS api behind Cloud9 - Stack Overflow
I am creating a simple rest api with hapi and using Cloud9 IDE. I can access the API endpoint within the same browser...
Read more >
Azure PowerShell release notes - Microsoft Learn
Learn about all of the latest updates to the Azure PowerShell modules.
Read more >
Once granted access, you can use the Figma API to
Endpoints allow you to request files, images, file versions, users, comments, team projects and project files. Once granted access, you can use the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found