I have a legacy app created using Create React App and i have to add CSP headers. I found that i can add it via adding vercel.json to root folder.
File looks like this:
After pushing changes build fails with error from title:
For development i use JetBrains Raider on Windows 10, file is UTF-8 encoded and there are no tricky white space characters.
I even tried to reduce the file to:
There’s no trailing comma after the "value" field.
The "source" field uses a regex pattern to match all routes.
The "value" for the CSP header doesn’t have a semicolon at the end.
If you’re still encountering issues:
Use a JSON validator (like JSONLint) to check your vercel.json file for any syntax errors.
Try creating the vercel.json file from scratch, typing it out manually instead of copy-pasting.
If you’re using Windows, ensure that your text editor is set to use LF (Line Feed) instead of CRLF (Carriage Return Line Feed) for line endings.
You can also try adding the CSP headers directly in your React application using the react-helmet library if the vercel.json approach continues to fail.
If none of these solutions work, you might want to try deploying a minimal version of your app with just the vercel.json file to isolate the issue.