static-web-apps-cli: Dependency on json.schemastore.org breaks CLI

The SWA CLI currently fails and stops after a few seconds, because either the latency of https://json.schemastore.org/staticwebapp.config.json is too high or the service is not available. There should be no dependency on an online resource to be available for local development. From the logs it seems like it should continue to work without validation, but it currently doesn’t.

Logs:

[swa] network timeout at: https://json.schemastore.org/staticwebapp.config.json
[swa] ✖ Failed to load staticwebapp.config.json schema. Continuing without validation!
[swa] node "C:\Users\USER\AppData\Local\pnpm\global\5\.pnpm\@azure+static-web-apps-cli@1.1.6\node_modules\@azure\static-web-apps-cli\dist\msha\server.js" exited with code 0
--> Sending SIGTERM to other processes..
[dataApi] cd "C:\repos\APP\data-api" && "C:\Users\USER\.swa\dataApiBuilder\0.9.7\Microsoft.DataApiBuilder.exe" start -c staticwebapp.database.config.json --no-https-redirect exited with code 1
--> Sending SIGTERM to other processes..
[run] cd "C:\repos\APP\app" && pnpm dev exited with code 1
✖ SWA emulator stopped because the --run command exited with code 1.

My suggestion would be to increase the timeout for the request and to fix the bug that stops the CLI from working without validation.

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Reactions: 25
  • Comments: 21 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for all of your feedback. We are going to have a local backup schema as a fallback option if the download fails. I have reopened the issue #754, and the fix will come soon.

Another workaround is to use version 1.1.4.

Pinning the version to v1.1.4 while waiting on the fix seems to have fixed the issue for us (it still fails to load the schema, but does not fail the whole deployment because of it)

Hi @jancimajek, in v1.1.4 SWA-CLI skipped validation and continued deploying if timeout. However, it will make routing to not work. So I recommend not to skip validation, but use the 1.1.7-alpha version with my fix instead: https://github.com/Azure/static-web-apps-cli/issues/754#issuecomment-1977411452. The official release will come soon.

Another workaround is to use version 1.1.4.

What is the current status for resolving this issue @cjk7989 ?

Same problem here:

network timeout at: https://json.schemastore.org/staticwebapp.config.json
[swa] ✖ Failed to load staticwebapp.config.json schema. Continuing without validation!
(...)
✖ SWA emulator stopped because API server exited with code 1.

Also having this problem, since the 1st of March:

[swa] network timeout at: https://json.schemastore.org/staticwebapp.config.json
[swa] ✖ Failed to load staticwebapp.config.json schema. Continuing without validation!
[swa] node "<local path>\node_modules\@azure\static-web-apps-cli\dist\msha\server.js" exited with code 0    
--> Sending SIGTERM to other processes..
[api] cd "<local path>" && "func" start --cors "*" --port <host port>  exited with code 1
✖ SWA emulator stopped because API server exited with code 1.

Heavy plus one! We use this CLI deploy our production sites, so this is really blocking us from release

It is this line that makes this fail. It should not send true as the second argument as true is used to signal logger.error to exit the program.

https://github.com/Azure/static-web-apps-cli/blob/f9f9b7e92f5fb03cf9b75626377f951a5f85cd5d/src/core/utils/user-config.ts#L108

Anyone using Github Actions could use https://github.com/Azure/static-web-apps-deploy directly instead of the SWA CLI (as mentioned in #754).

Don’t know if this helps anyone, but I did the following this morning to unblock all of our deployment pipelines.

  1. Download this repo
  2. Change this line to pass false, as the second argument to logger.error https://github.com/Azure/static-web-apps-cli/blob/f9f9b7e92f5fb03cf9b75626377f951a5f85cd5d/src/core/utils/user-config.ts#L108
  3. Build and deploy to my own private registry
    1. Change the name in package.json to @myprivateorg/static-web-apps-cli-hotfix
    2. npm run build
    3. npm pack
    4. npm publish
  4. Change my deploy pipelines to use npx @myprivateorg/static-web-apps-cli-hotfix ... instead of npx @azure/static-web-apps-cli

This worked for us, but some maintainer said here that this might not work 🤷 I guess do this at your own risk or whatever.