static-web-apps-cli: Failed to load staticwebapp.config.json schema on start
I’m using the latest version 1.1.4
Are you accessing the CLI from the default port :4280
?
- No, I am using a different port number (
--port
) and accessing the CLI from that port - Yes, I am accessing the CLI from port
:4280
Describe the bug
When starting an app with swa start
I get WARNING: Failed to load staticwebapp.config.json schema. Continuing without validation!
.
Even if it’s just a warning and is referring to the schema file (not the config itself) staticwebapp.config.json
doesn’t work as expected. e.g. none of the routes declared is working.
To Reproduce Steps to reproduce the behavior:
- Go to any swa app
- Type in command ‘swa start’
- See warning in console
- Check in browser any routes declared -> won’t work.
Expected behavior
staticwebapp.config.json
to work. Routes and any other settings declared to work.
Desktop (please complete the following information):
- OS: Windows
- Version: 11
Additional context After investigating this issue i have discovered that the URL used to load the config schema is hardcoded: https://github.com/Azure/static-web-apps-cli/blob/affefb24872286a542fe7bbd54340648ec3294d0/src/core/utils/user-config.ts#L168C13-L168C13 . At this moment, the website https://www.schemastore.org/ which is hosting the schema file, is down (error 503). Allowing loading the schema file only from a single website has created a single point of failure which we are experiencing right now.
staticwebapp.config.json
has a property $schema
, but as you can see the value is not used for actually loading the schema.
My suggestion is to allow the user to provide a value for $schema
(in order to no longer depend on https://www.schemastore.org/ ).
Thank you.
Edit: there’s currently an issue on Schemastore repository: https://github.com/SchemaStore/schemastore/issues/3303
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Reactions: 13
- Comments: 71 (6 by maintainers)
Hi all, the fix has been merged in PR #808. In summary, we added a logic to load static-web-apps-cli/schema/staticwebapp.config.json as a backup, in case https://json.schemastore.org/staticwebapp.config.json get timeout again.
Before a new version of swa-cli is released, you can feel free to download and test it from GitHub. Here are the steps:
Thanks a lot for checking if this update works for you.
The solution shouldn’t be reliant upon any specific host, MS controlled or otherwise. Its a dependency that can cause the current pain points many of us are receiving.
Why not ship a fallback schema with the tool, kept up to date with each update.
Better yet, don’t perform any validation at all at deploy time. If the schema is messed up in the config file at the time of deployment that is a fault of something that should have been fixed and adjusted at build time. And even then, there shouldn’t be any hard-coded dependency on a remote server being available.
Here’s a simple fix that skips the validation (as the message says) instead of killing process. Some reordering of rows and missing schema returns config instead of null. File: node_modules/@azure/static-web-apps-cli/dist/core/utils/user-config.js
Temporary solution (what I did):
%userprofile%\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\dist\core\utils
(for Windows).user-config.js
.https://json.schemastore.org/staticwebapp.config.json
.staticwebapp.config.json
to blob storage (for example) or use my file:https://stcuberdonintegration.blob.core.windows.net/assets/staticwebapp.config.json
(Will be removed in 24H)https://json.schemastore.org/staticwebapp.config.json
with your remote path.Can we skip accessing the network for the commands that does not require it? I am often find myself working on the plane with unstable internet connection. I don’t understand why do I need to download anything from the Internet if I just want to test the app. For deployment we may have additional arguments.
Thanks for the feedback. It’s an intermittent bug but occurs more common recently. We are going to have a local backup schema as a fallback option if the download fails. The fix will come soon.
@cjk7989 this should really be reopened, https://json.schemastore.org being down caused a monorepo with hundreds of devs to block all pull requests. We should be able to provide a local fallback.
Good morning. Can’t locally start my Azure static web app because …
network timeout at: https://json.schemastore.org/staticwebapp.config.json
The schema store is just sending 429 and 503s
I agree that this is a weird network dependency on what should should be “Airplane mode” type local dev work.
It’s happening, right now… AGAIN!!!
Please, reopen and FIX this.
I followed @LiamOSullivan steps above but rather than putting in a new blob address I increased the time out
Hi all, we have published swa-cli@v1.1.5, which will throw an error if staticwebapp.config.json schema is failed to be download. And we plan to design a fallback method to completely fix the issue in the next version. Thanks very much for your feedback and suggestions.
…
That is what the container image
mcr.microsoft.com/appsvc/staticappsclient:stable
is for 😉 This is not the right place to request a certain tool to be open sourced. If you want to request other tools for the deployment or something to be open sourced, you could open a separate issue for that.The important part is that the SWA CLI should not be part of production release tooling and that the tools for that are the container image and the GitHub action. There is currently no dependency on the CLI for production deployments.
I think this is the proposal that should be given the most preferential treatment.
Really? Is it fixed so that when the schemastore isn’t available it at least throws some kind of error and does not deploy a not working swa?.. I think it is not fixed.
Solved with workaround!!
After few hrs of struggle and understand I finally got it work by storing schema to different host and pointing updating the same in
user-config.js
. Thanks @cjk7989Note: For mac os, path for file is:
/usr/local/lib/node_modules/@azure/static-web-apps-cli/dist/core/utils/user-config.js
. depends on node installation directory. change the schemaUrl in the file to your hosted schema path.Those who need the content of the schema to host, I have a copy of it at:
https://anuraggandhi.com/schema-swa.config.json
. (please don’t use it directly from this host. It will be removed shortly.)That is not correct @nathanblair, the GitHub action doesn’t rely on the CLI at all, which is why that is the preferred way for production deployments. The GitHub action is just a wrapper around the SWA container (
mcr.microsoft.com/appsvc/staticappsclient:stable
) and you can currently use the SWA container as well as the GitHub action without problems. There is no production tooling around SWA relying on the CLI, as the SWA CLI is mainly for local development.Removing the “true” from logger_1.logger.error to skip validation will cause the routing to not work. I recommend the two temporary solutions mentioned by @zainzafar90, to save the schema into Azure blob storage, or set the timeout to a larger value.
I probably understood this problem. In loadSWAConfigSchema(), there is a process to load data from the following SchemaURL, right?
Currently, it seems that the data delivery for this URL is very slow. This is causing a timeout.
I agree with @avalor1 . We should not depend on a third-party service which can become unavailable without notice.
Edit: My understanding is that the purpose of https://json.schemastore.org/ is to be used by various IDEs and VSCode extensions and SWA-CLI is using it for essential functionalities (build and deploy); even then it just logs a warning if it’s unavailable. At the very least, on deployment it should throw an error when the service is unavailable. This way we’ll avoid having broken SWAs in production. (and again wait for the service to become available 🙃)
I can confirm that issue as well on 1.1.4. Also, the fix posted by @aresofficial is working for me.
That’s really strange, how Azure position Static Web Apps as production-ready service, where your app can be totally inaccessible because of downtime on 3rd party service. Moreover, not a single failure was seen,
swa deploy
will silently deploy your app and destroy all routes. That’s “amazing”Seeing the same problem. This does also affect the
swa deploy
command leading to a not working SWAI’m also running into this issue. Just had a new deployment, and users are redirected to 404 page if they try to access links directly or refresh the page.
Close it as swa-cli@v1.1.7 has been released and fixed this issue, thanks very much for all your feedback and suggestions.
I followed these instructions from cjk7989. This installs 1.17-alpha ,which solved the problem for me.
For SWA deployment in a Azure DevOps CI/CD pipeline, the recommended way is to use the “AzureStaticWebApp” task (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-static-web-app-v0?view=azure-pipelines). The CLI is mainly for local development not for production deployments. The same action exists for Github, Gitlab and Bitbucket and as container for other deployment systems.
I understand, I also have the same set of frustration as my deployment delayed by many hrs due to this. Hope MS will fix it intelligently and will not rely on 3rd party sites for their production ready tools.
Better solution, i think: MS should host the schemas themselves to a relied host and use them for their tools. They should take care of updating the schema when needed.
Thank you. I have found another way to solve it. And it works without hosting the
staticwebapp.config.json
file So instead of simply replacing the URL, I increased the timeout to5 minutes
instead of just10 seconds
, as the only issue was I was able to load the file in browser but it would take more than 10 seconds.Here’s how you can do it:
user-config.js
const schemaUrl = "https://json.schemastore.org/staticwebapp.config.json";
and below there’s a line with timeout set to10 * 1000
10
to whatever number you think worksPS. Finding user-config was tricky because it was installed globally and since I am using nvm mine was located at
~/.nvm/versions/node/v18.18.0/lib/node_modules/@azure/static-web-apps-cli/dist/core/utils/user-config.js
Saved my teams morning productivity, thank you!
Currently swa fails to start locally because of this error:
@cjk7989 Friday, I was able to bring my SWA up just fine locally for testing during development. Tonight, I ran everything with the exact same configuration and I get this error. Are there really no parameters I could supply to have it not reach out to a spotty third party?
Thank you for solution!
I was able to patch @azure/static-web-apps-cli for my deployment pipelines to use custom url instead of https://json.schemastore.org/staticwebapp.config.json.
patches/@azure+static-web-apps-cli+1.1.6.patch
package.json
.env
The current error is still “Continuing without validation”. That will confuse users since it’s aborting execution.
The issue is not fixed, Static Web Apps CLI is still unstable. It’s only a matter of time before problem recurs (e.g. because of outage on schemastore)
Deployment should at least not silently destroy routes, otherwise Static Web Apps can’t be production-ready (as now). @cjk7989 can you please escalate this issue?
…
Just to clarify some things in case anyone stumbles upon this issue. Neither the container image nor the GitHub/GitLab/etc. task has any dependency on the CLI and this issue is a pure CLI issue (fixed in 1.1.7). The only part of the CLI that uses the same tools as the container image is the
deploy
command, which still works without any problems as the validation in the deployment tooling has no dependency on the external schema and has it’s own schema validation written in C#. Currently the CLI lacks support for some parameters and variables for deployment, which is why the container image and the task are the recommended options. As the container image is available in the public MS registry, there is no requirement to use actions/tasks for deployment and like with many other projects, the container image can just be used locally if no CI system is available. I totally support improving the CLIdeploy
command to a level where it has the same deployment capabilities as the image/task, because not everyone has the same knowledge of containers and it would thereby reduce friction.If you want to dive deeper or get a better understanding for the SWA-Client executable feel free to follow up offline @nathanblair.
@PothieuG I don’t think the npm package has been published yet: https://www.npmjs.com/package/@azure/static-web-apps-cli?activeTab=versions.
I imagine it’ll get published later once @cjk7989 see’s that it’s been tested by some individuals here, see the request here. I’m also guessing there are timezone limitations too
Not everyone has ability to use the GitHub Action for their deployment and should not be required to do so. Again, the underlying tool should be open sourced to begin with
I hope that we can settle on the fact that “local development” does not require fetching anything from the internet. 😃
One other interesting observation that I would like to point out: I didn’t know that there is a validation until I went offline. I am not clear on why this is required and can this be optional? (activated using
--strict
or--validate
arg)In any case making
start
command not rely on the internet - that is my main request.Thank you!
All of the other options rely on this under the hood. So doing anything that doesn’t rely on this isn’t an option. The real tool, the StaticClientSites binary, is kept closed source. Otherwise I’d just modify and build that directly myself and use it. This CLI tool and any other cli tool that publishes to Azure Static Sites use that closed-source binary because it’s the only way to get resources to Azure Static Sites.
@softgandhi
Yes, I do not intend to use this in a production environment, but rather to use it for development to temporarily deal with issues that are currently occurring.
I think the following measures are necessary. Add processing that allows individuals to specify Schema for development by dividing the URL that distributes Schema into multiple parts or as an option.
Please have an image like the following.
A quick way to use the CLI until this is resolved is to remove the “true” parameter to the logger.error method, as this causes the script to exit:
static-web-apps-cli/src/core/utils/user-config.ts
This:
logger_1.logger.error(`Failed to load staticwebapp.config.json schema. Continuing without validation!`);
instead of this:logger_1.logger.error(`Failed to load staticwebapp.config.json schema. Continuing without validation!`, true);
Credit to @cristianbretti
I disabled validation until this gets resolved:
Having a way of doing local validation is not the solution. We would still see default pipelines to fail each time someone decides to attack schemas tore.org
I think validation shloud be non-fatal at build time, it will be redone by swa api during publish. An optional parameter to force fatal errors on validation would be nice to have for some scenarios.
Yes and no… someone threw more hardware on the problem so it works for now but the problem persists. One still depends on the availability of https://www.schemastore.org/. Not quite what i would call “fixed” 😃
Confirm this fix by @aresofficial for the issue I observed…