Symfony stops with: A YAML file cannot contain tabs as indentation
A YAML file cannot contain tabs as indentation.Short answer
The YAML parser found a tab as the first character of a line. YAML indentation must be spaces only. The exception names the line number: open that line, replace the tab with spaces, and set your editor to insert spaces for the Tab key in .yaml files.
Fix it fast
1Find out which cause you have
The exception includes the line number and the offending line. Print tabs in that file, showing the line numbers, to find every one.
grep -nP '^\t' config/routes.yaml config/services.yaml2Match what you see, then jump to its fix
What does the error look like?
A YAML file cannot contain tabs as indentation.Symfony\Component\Yaml\Exception\ParseException
Cause 1 of 2
The editor inserted a tab when you pressed Tab
1Check
The Symfony parser checks whether a line begins with a tab character and throws this exception. Symfony's YAML documentation says indentation must be done with spaces, never with tabs.
grep -rnP '^\t' config/ translations/2Fix
Replace each leading tab with spaces (two or four, the same as the other lines) and keep one width in the file. Set the editor to insert spaces for .yaml files.
# convert leading tabs to 4 spaces in one file (GNU sed)
sed -i 's/^\t/ /' config/routes.yaml
# .editorconfig
[*.{yaml,yml}]
indent_style = space
indent_size = 43Verify
Clear the cache and load a page again.
php bin/console cache:clearConfirmed by symfony.com
Cause 2 of 2
YAML is generated or pasted from code, a template or a document
1Check
Text copied from a web page, a document, or a PHP string built with \t keeps its tabs. The parser sees the tab at the start of a line in the string, not in a file.
var_dump(str_contains($yamlString, "\t"));2Fix
Build the string with spaces, or convert leading tabs before parsing.
$yamlString = preg_replace('/^\t+/m', ' ', $yamlString);
$data = Symfony\Component\Yaml\Yaml::parse($yamlString);3Verify
Parse again. It returns an array.
var_dump(is_array($data));Confirmed by raw.githubusercontent.com
How do I stop it coming back?
- Add an .editorconfig that sets indent_style to space for yaml and yml files.
- Add a grep for leading tabs in YAML files to CI, so a tab fails the build and not the deploy.
- Never indent YAML in a word processor or a chat window and paste it back.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Apache returns 403 when a URL contains %3F
a request like /page%3Fname=test is refused while /page?name=test works
Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.
2 causes, each with a fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix