Hello guys,
I am trying to use the plugin https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-yaml.
I finally correctly created the queries with graphql, but there's a problem when I try to build the application in a production environtment.
When I tried to build, the netlify command line printed this error:
YAMLException: expected a single document in the stream, but found more
The most curious thing is that, as i told you before, my queries to yaml files were working correctly, but I have just discovered that, deleting the .cache folder and running gatsby develop or gatbsy build, it returns the same error, but if i run this command a second time, everything works again.
How can I resolve this?
Thanks a lot for your help!
The folder structure for yml files is:
โโโ _src
โ โโโ _data
โ โโโ _generic
โ โโโ index.yml
โ โโโ services.yml
โ โโโ ...
The query:
export const indexQuery = graphql`
query allGeneric{
allGenericYaml ( filter: { published: { eq : true }, front_page: { eq : true} } ){
edges {
node {
title
path
}
}
}
}
`;
The yaml content file structure is something like this:
path: '/'
date: 2017-07-07T12:00:00Z
title: Inicio
published: true
front_page: false
cover: 'img/page/home.jpg'
navigation:
- name: main
order: 1
level: 1
hidden: false
System:
OS: Windows 10
CPU: x64 Intel(R) Core(TM) i7-3930K CPU @ 3.20GHz
Binaries:
npm: 6.1.0 - C:\Users\harri\AppData\Roaming\npm\npm.CMD
Browsers:
Edge: 41.16299.492.0
npmPackages:
gatsby: next => 2.0.0-beta.19
gatsby-plugin-react-helmet: next => 3.0.0-beta.3
gatsby-source-filesystem: ^1.5.39 => 1.5.39
gatsby-transformer-yaml: ^1.5.18 => 1.5.18
gatsby-config.js:
module.exports = {
siteMetadata: {
title: 'Gatsby Default Starter',
},
plugins: [
'gatsby-plugin-react-helmet',
`gatsby-transformer-yaml`,
{
resolve: `gatsby-source-filesystem`,
options: {
path: `./src/data/`,
},
},
],
}
package.json:
{
"name": "gatsby-starter-default",
"description": "Gatsby default starter",
"version": "1.0.0",
"author": "Kyle Mathews <[email protected]>",
"dependencies": {
"gatsby": "next",
"gatsby-plugin-react-helmet": "next",
"gatsby-source-filesystem": "^1.5.39",
"gatsby-transformer-yaml": "^1.5.18",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-helmet": "^5.2.0"
},
"keywords": [
"gatsby"
],
"license": "MIT",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write 'src/**/*.js'",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"prettier": "^1.12.0"
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-default"
}
}
Hi @m-allanson,
No, I don't have multiple documents inside the yaml file but neither I have the --- divider, is this divider necessary even if I have just one document inside the file with yml extension?
My yaml files only contains what I wrote before, in the section "The yaml content file structure is something like this".
Thanks for your help.
I have just tried modifiyng my .yml files for adding --- but it still not working.
I have been trying to get more information about the issue and I can see that the build is failing when the file .cache/redux-state.json doesn't exists.
Also, when I clear the cache folder and execute gatbsy develop, the error is shown by console, and after this, the console gets stuck with the message 'source and transform nodes'
I will to try go deeper.
Ok, this is embarrasing ๐
I have solved my problem making a bit of debugging, finally I found that I had another .yml files from other folder with the dividers --- and that's all.
Now the deploy is working fine.
Thanks a lot!
I'm glad you got it worked out! Maybe Gatsby should support Yaml files that contain multiple documents? I'm not really sure what impact that would have on the Yaml transformer.
I also met this problem when I run this code:
let obj = yaml.safeLoad(fs.readFileSync("F:/Demo1.yml", "utf8"));
and I do not have another .yml files in current folder, I don't know what to do now...
I'm glad you got it worked out! Maybe Gatsby should support Yaml files that contain multiple documents? I'm not really sure what impact that would have on the Yaml transformer.
if the --- notation is to indicate a document, then why not support several documents. For the application I am working on I need to support several documents in one file, it makes a lot of sense.
I'm glad you got it worked out! Maybe Gatsby should support Yaml files that contain multiple documents? I'm not really sure what impact that would have on the Yaml transformer.
if the
---notation is to indicate a document, then why not support several documents. For the application I am working on I need to support several documents in one file, it makes a lot of sense.
Agree. Loading from a .yaml file with a --- separator should return an array of yamls.
Thanks, the problem is solved