Jekyll config.yml did not find expected key while parsing a block mapping
Asked Answered
I

4

8

I'm getting this error in the command line terminal:

did not find expected key while parsing a block mapping at line 18 column 7

My jekyll _config.yml YAML file looks like this:

title: Oliver Williams - Portfolio
url: "http://yourdomain.com" # the base hostname & protocol for your site

# Build settings
markdown: kramdown
permalink: /:title

defaults:
  -
    scope:
      path: "" # an empty string here means all files in the project
      type: "posts" # previously `post` in Jekyll 2.2.
    values:
      layout: "post"

       -
    scope:
      path: "" # an empty string here means all files in the project
      type: "pages" 
    values:
      layout: "page"
Isomer answered 11/10, 2015 at 14:15 Comment(3)
These errors are fickle and it often reports the wrong line.Impatient
Fickle yaml errors I resolved by going back to tab delimited text for one project.Anglophobia
I had the same error but because I had added an apostrophe in one of the string configs and the formatting went crazy since we also use apostrophe to mean start/end of string. I just needed to replace the apostrophe at string start/end to a double quote sign and then the apostrophe sat comfortably within the string config.Incompletion
B
8

I'm not sure of your formating/indentation for _config.yml.

This one is correct :

title: Oliver Williams - Portfolio
url: "http://yourdomain.com"
markdown: kramdown 
permalink: /:title

defaults: 
  - 
    scope: 
      path: "" 
      type: "posts" 
    values: 
      layout: "post"
  -
    scope:
      path: ""
      type: "pages" 
    values:
      layout: "page"
Burnejones answered 11/10, 2015 at 15:18 Comment(0)
W
6

The problem is in your second list element for defaults. The marker is indented too much, possible because you used a tab instead of a two spaces.

There is no reason to put the mappings that are elements of those lists on a separate line. You also don't have to indent list elements if the list is a mapping value. Nor is it necessary to quote simple scalars like "posts", "page", etc. (You don't have that for your title value either)

So you can do:

title: Oliver Williams - Portfolio
url: http://yourdomain.com   # the base hostname & protocol for your site

# Build settings
markdown: kramdown
permalink: /:title

defaults:
- scope:
    path: ''         # an empty string here means all files in the project
    type: posts      # previously `post` in Jekyll 2.2.
  values:
    layout: post
- scope:
    path: ''         # an empty string here means all files in the project
    type: pages
  values:
    layout: page

which is equivalent to your input (corrected for the overindented -)

Whin answered 11/10, 2015 at 15:39 Comment(0)
T
0

Somewhere in your YAML, you have extra spaces (or not enough spaces) before a key value.

this YAML linter may help as it tells you a correct line with error(if any): https://jsonformatter.org/yaml-formatter.

Tersanctus answered 27/3, 2020 at 0:3 Comment(0)
G
-1

I had to replace "but wait, there's more!" with "but wait, there is more!", which was actually enclosed in single quotes, the apostrophe in the text string breaking it!

Grazynagreabe answered 18/9, 2022 at 16:26 Comment(2)
Your answer is unrelated to the problem in the question.Rori
It related to the commenter "vishwarajanand Jun 13, 2019 at 13:12" which was the solution to and clarification of the problem we evidently had that brought us both here.Grazynagreabe

© 2022 - 2024 — McMap. All rights reserved.