Error on importing images from Wordpress to GatsbyJS V2












0















I am new to Gatsby and React in general and I can't seem to figure out how to display images using Gatsby Sharp with the Wordpress source plugin.



Using the setup on tutorials and example code I have this on my setup.



on my gatsby-config.js:



    module.exports = {
siteMetadata: {
title: 'Gatsby Default Starter',
},
plugins: [
'gatsby-plugin-react-helmet',
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
{
resolve: `gatsby-source-wordpress`,
options: {
/*
* The base URL of the WordPress site without the trailingslash and the protocol. This is required.
* Example : 'gatsbyjswpexample.wordpress.com' or 'www.example-site.com'
*/

baseUrl: `MYWORDPRESSSITE`,
// The protocol. This can be http or https.
protocol: `http`,
// Indicates whether the site is hosted on wordpress.com.
// If false, then the asumption is made that the site is self hosted.
// If true, then the plugin will source its content on wordpress.com using the JSON REST API V2.
// If your site is hosted on wordpress.org, then set this to false.
hostingWPCOM: false,
// If useACF is true, then the source plugin will try to import the WordPress ACF Plugin contents.
// This feature is untested for sites hosted on WordPress.com
useACF: true,
},
},
'gatsby-transformer-sharp',
'gatsby-plugin-sharp',
{
resolve: `gatsby-plugin-manifest`,
options: {
name: 'gatsby-starter-default',
short_name: 'starter',
start_url: '/',
background_color: '#663399',
theme_color: '#663399',
display: 'minimal-ui',
icon: 'src/images/gatsby-icon.png', // This path is relative to the root of the site.
},
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.app/offline
// 'gatsby-plugin-offline',
],
}


This is my query:



export const pageQuery = graphql`
query {
allWordpressPost{
edges {
node {
id
slug
title
content
excerpt
date
modified
featured_media {
localFile {
childImageSharp {
fluid(maxHeight: 300) {
base64
tracedSVG
aspectRatio
src
srcSet
srcWebp
srcSetWebp
sizes
originalImg
originalName
}
}
}
}
}
}
}
}`


and add the image on my index using this:



const IndexPage = ({data}) => (
<Layout>
{data.allWordpressPost.edges.map(({ node }) => (
<Img fluid={node.featured_image.localFile.childImageSharp.fluid} />

<h2 className="mt0">{node.title}</h2>
<p className="measure blogpost" dangerouslySetInnerHTML={{ __html: node.content }}></p>
))}
</Layout>
)


When on dev mode I receive a blank page and when I try to build it, I get an error.



WebpackError: TypeError: Cannot read property 'localFile' of undefined


I am not sure what I am missing at this point as I can see localFile on my graphql but I am hoping someone can point me to the right direction.










share|improve this question



























    0















    I am new to Gatsby and React in general and I can't seem to figure out how to display images using Gatsby Sharp with the Wordpress source plugin.



    Using the setup on tutorials and example code I have this on my setup.



    on my gatsby-config.js:



        module.exports = {
    siteMetadata: {
    title: 'Gatsby Default Starter',
    },
    plugins: [
    'gatsby-plugin-react-helmet',
    {
    resolve: `gatsby-source-filesystem`,
    options: {
    name: `images`,
    path: `${__dirname}/src/images`,
    },
    },
    {
    resolve: `gatsby-source-wordpress`,
    options: {
    /*
    * The base URL of the WordPress site without the trailingslash and the protocol. This is required.
    * Example : 'gatsbyjswpexample.wordpress.com' or 'www.example-site.com'
    */

    baseUrl: `MYWORDPRESSSITE`,
    // The protocol. This can be http or https.
    protocol: `http`,
    // Indicates whether the site is hosted on wordpress.com.
    // If false, then the asumption is made that the site is self hosted.
    // If true, then the plugin will source its content on wordpress.com using the JSON REST API V2.
    // If your site is hosted on wordpress.org, then set this to false.
    hostingWPCOM: false,
    // If useACF is true, then the source plugin will try to import the WordPress ACF Plugin contents.
    // This feature is untested for sites hosted on WordPress.com
    useACF: true,
    },
    },
    'gatsby-transformer-sharp',
    'gatsby-plugin-sharp',
    {
    resolve: `gatsby-plugin-manifest`,
    options: {
    name: 'gatsby-starter-default',
    short_name: 'starter',
    start_url: '/',
    background_color: '#663399',
    theme_color: '#663399',
    display: 'minimal-ui',
    icon: 'src/images/gatsby-icon.png', // This path is relative to the root of the site.
    },
    },
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.app/offline
    // 'gatsby-plugin-offline',
    ],
    }


    This is my query:



    export const pageQuery = graphql`
    query {
    allWordpressPost{
    edges {
    node {
    id
    slug
    title
    content
    excerpt
    date
    modified
    featured_media {
    localFile {
    childImageSharp {
    fluid(maxHeight: 300) {
    base64
    tracedSVG
    aspectRatio
    src
    srcSet
    srcWebp
    srcSetWebp
    sizes
    originalImg
    originalName
    }
    }
    }
    }
    }
    }
    }
    }`


    and add the image on my index using this:



    const IndexPage = ({data}) => (
    <Layout>
    {data.allWordpressPost.edges.map(({ node }) => (
    <Img fluid={node.featured_image.localFile.childImageSharp.fluid} />

    <h2 className="mt0">{node.title}</h2>
    <p className="measure blogpost" dangerouslySetInnerHTML={{ __html: node.content }}></p>
    ))}
    </Layout>
    )


    When on dev mode I receive a blank page and when I try to build it, I get an error.



    WebpackError: TypeError: Cannot read property 'localFile' of undefined


    I am not sure what I am missing at this point as I can see localFile on my graphql but I am hoping someone can point me to the right direction.










    share|improve this question

























      0












      0








      0








      I am new to Gatsby and React in general and I can't seem to figure out how to display images using Gatsby Sharp with the Wordpress source plugin.



      Using the setup on tutorials and example code I have this on my setup.



      on my gatsby-config.js:



          module.exports = {
      siteMetadata: {
      title: 'Gatsby Default Starter',
      },
      plugins: [
      'gatsby-plugin-react-helmet',
      {
      resolve: `gatsby-source-filesystem`,
      options: {
      name: `images`,
      path: `${__dirname}/src/images`,
      },
      },
      {
      resolve: `gatsby-source-wordpress`,
      options: {
      /*
      * The base URL of the WordPress site without the trailingslash and the protocol. This is required.
      * Example : 'gatsbyjswpexample.wordpress.com' or 'www.example-site.com'
      */

      baseUrl: `MYWORDPRESSSITE`,
      // The protocol. This can be http or https.
      protocol: `http`,
      // Indicates whether the site is hosted on wordpress.com.
      // If false, then the asumption is made that the site is self hosted.
      // If true, then the plugin will source its content on wordpress.com using the JSON REST API V2.
      // If your site is hosted on wordpress.org, then set this to false.
      hostingWPCOM: false,
      // If useACF is true, then the source plugin will try to import the WordPress ACF Plugin contents.
      // This feature is untested for sites hosted on WordPress.com
      useACF: true,
      },
      },
      'gatsby-transformer-sharp',
      'gatsby-plugin-sharp',
      {
      resolve: `gatsby-plugin-manifest`,
      options: {
      name: 'gatsby-starter-default',
      short_name: 'starter',
      start_url: '/',
      background_color: '#663399',
      theme_color: '#663399',
      display: 'minimal-ui',
      icon: 'src/images/gatsby-icon.png', // This path is relative to the root of the site.
      },
      },
      // this (optional) plugin enables Progressive Web App + Offline functionality
      // To learn more, visit: https://gatsby.app/offline
      // 'gatsby-plugin-offline',
      ],
      }


      This is my query:



      export const pageQuery = graphql`
      query {
      allWordpressPost{
      edges {
      node {
      id
      slug
      title
      content
      excerpt
      date
      modified
      featured_media {
      localFile {
      childImageSharp {
      fluid(maxHeight: 300) {
      base64
      tracedSVG
      aspectRatio
      src
      srcSet
      srcWebp
      srcSetWebp
      sizes
      originalImg
      originalName
      }
      }
      }
      }
      }
      }
      }
      }`


      and add the image on my index using this:



      const IndexPage = ({data}) => (
      <Layout>
      {data.allWordpressPost.edges.map(({ node }) => (
      <Img fluid={node.featured_image.localFile.childImageSharp.fluid} />

      <h2 className="mt0">{node.title}</h2>
      <p className="measure blogpost" dangerouslySetInnerHTML={{ __html: node.content }}></p>
      ))}
      </Layout>
      )


      When on dev mode I receive a blank page and when I try to build it, I get an error.



      WebpackError: TypeError: Cannot read property 'localFile' of undefined


      I am not sure what I am missing at this point as I can see localFile on my graphql but I am hoping someone can point me to the right direction.










      share|improve this question














      I am new to Gatsby and React in general and I can't seem to figure out how to display images using Gatsby Sharp with the Wordpress source plugin.



      Using the setup on tutorials and example code I have this on my setup.



      on my gatsby-config.js:



          module.exports = {
      siteMetadata: {
      title: 'Gatsby Default Starter',
      },
      plugins: [
      'gatsby-plugin-react-helmet',
      {
      resolve: `gatsby-source-filesystem`,
      options: {
      name: `images`,
      path: `${__dirname}/src/images`,
      },
      },
      {
      resolve: `gatsby-source-wordpress`,
      options: {
      /*
      * The base URL of the WordPress site without the trailingslash and the protocol. This is required.
      * Example : 'gatsbyjswpexample.wordpress.com' or 'www.example-site.com'
      */

      baseUrl: `MYWORDPRESSSITE`,
      // The protocol. This can be http or https.
      protocol: `http`,
      // Indicates whether the site is hosted on wordpress.com.
      // If false, then the asumption is made that the site is self hosted.
      // If true, then the plugin will source its content on wordpress.com using the JSON REST API V2.
      // If your site is hosted on wordpress.org, then set this to false.
      hostingWPCOM: false,
      // If useACF is true, then the source plugin will try to import the WordPress ACF Plugin contents.
      // This feature is untested for sites hosted on WordPress.com
      useACF: true,
      },
      },
      'gatsby-transformer-sharp',
      'gatsby-plugin-sharp',
      {
      resolve: `gatsby-plugin-manifest`,
      options: {
      name: 'gatsby-starter-default',
      short_name: 'starter',
      start_url: '/',
      background_color: '#663399',
      theme_color: '#663399',
      display: 'minimal-ui',
      icon: 'src/images/gatsby-icon.png', // This path is relative to the root of the site.
      },
      },
      // this (optional) plugin enables Progressive Web App + Offline functionality
      // To learn more, visit: https://gatsby.app/offline
      // 'gatsby-plugin-offline',
      ],
      }


      This is my query:



      export const pageQuery = graphql`
      query {
      allWordpressPost{
      edges {
      node {
      id
      slug
      title
      content
      excerpt
      date
      modified
      featured_media {
      localFile {
      childImageSharp {
      fluid(maxHeight: 300) {
      base64
      tracedSVG
      aspectRatio
      src
      srcSet
      srcWebp
      srcSetWebp
      sizes
      originalImg
      originalName
      }
      }
      }
      }
      }
      }
      }
      }`


      and add the image on my index using this:



      const IndexPage = ({data}) => (
      <Layout>
      {data.allWordpressPost.edges.map(({ node }) => (
      <Img fluid={node.featured_image.localFile.childImageSharp.fluid} />

      <h2 className="mt0">{node.title}</h2>
      <p className="measure blogpost" dangerouslySetInnerHTML={{ __html: node.content }}></p>
      ))}
      </Layout>
      )


      When on dev mode I receive a blank page and when I try to build it, I get an error.



      WebpackError: TypeError: Cannot read property 'localFile' of undefined


      I am not sure what I am missing at this point as I can see localFile on my graphql but I am hoping someone can point me to the right direction.







      wordpress reactjs gatsby






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 10:50









      Jasper DyJasper Dy

      33




      33
























          1 Answer
          1






          active

          oldest

          votes


















          0














          In the GraphQL query it has node.featured_media and in your React code you're doing node.featured_image



          Maybe its that??






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298438%2ferror-on-importing-images-from-wordpress-to-gatsbyjs-v2%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            In the GraphQL query it has node.featured_media and in your React code you're doing node.featured_image



            Maybe its that??






            share|improve this answer




























              0














              In the GraphQL query it has node.featured_media and in your React code you're doing node.featured_image



              Maybe its that??






              share|improve this answer


























                0












                0








                0







                In the GraphQL query it has node.featured_media and in your React code you're doing node.featured_image



                Maybe its that??






                share|improve this answer













                In the GraphQL query it has node.featured_media and in your React code you're doing node.featured_image



                Maybe its that??







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 9 at 19:29









                SarahSarah

                638




                638






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298438%2ferror-on-importing-images-from-wordpress-to-gatsbyjs-v2%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    List item for chat from Array inside array React Native

                    Thiostrepton

                    Caerphilly