static-web-apps-cli icon indicating copy to clipboard operation
static-web-apps-cli copied to clipboard

The following error was encountered: Unexpected token '', "{ "na"... is not valid JSON

Open mla157 opened this issue 10 months ago • 1 comments

SWA Version: 2.0.4

Describe the bug When I run swa deploy or swa I get a JSON validation error, even my JSON's config files for the staticwebapp-config.json are all valid json. With this state I can not deploy a SWA with a config.

To Reproduce

  1. Place a json with the name "staticwebapp.config.json" in our "app" folder with the content {}
  2. Run swa deploy

The following error occurs on my end:

WARNING: Failed to read staticwebapp.config.json configuration from: C:\folder1\folder2\folder3\client\staticwebapp.config.json

✖ The following error was encountered: Unexpected token '', "{}" is not valid JSON Please fix the above error and try again to load and use the configuration. Read more: https://aka.ms/swa/config-schema

At this state the staticwebapp.config.json only contains {} But I tried configurations like the this one, and they not working too.

{
    "navigationFallback": {
        "rewrite": "/index.html"
    }
}

Error Message:

✖ The following error was encountered: Unexpected token '', "{ "na"... is not valid JSON

Expected behavior Deployment Working

Desktop (please complete the following information):

  • OS: Windows
  • Version PS7

Additional context Add any other context about the problem here.

mla157 avatar Mar 04 '25 10:03 mla157

The problem is the following: The JSON parser only accepts hardcoded UTF-8 and not UTF-8 with BOM for example. I think It is needed, that the JSON parsers tries multiple encodings.

mla157 avatar Mar 04 '25 13:03 mla157