Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError on first run after install #10

Open
eduoliveira85 opened this issue Apr 24, 2020 · 2 comments
Open

TypeError on first run after install #10

eduoliveira85 opened this issue Apr 24, 2020 · 2 comments

Comments

@eduoliveira85
Copy link

What was done

I've installed and copied gatsby-browser.js to my project root folder, then created hooks for each of the relations I'd use it with Tina CMS: for blog post authors, categories and tags.
You can see the files below.

gatsby-browser.js

import './src/css/tailwind.css';
import './src/scss/default.scss';
//import TinaCMSConditionField from 'tinacms-condition-field';
import TinaCMSRelationField from 'tinacms-relation-field';
//import TinaCMSFileField from 'tinacms-file-field';

import useAuthors from './src/hooks/useAuthors'
import useCategories from './src/hooks/useCategories'
import useTags from './src/hooks/useTags'

export const onClientEntry = () => {
  //const conditionField = new TinaCMSConditionField(window.tinacms);
  //
  //conditionField.install();

  const relationField = new TinaCMSRelationField(window.tinacms);

  relationField.install([{
    name: 'authors',
    hook: useAuthors,
    itemProps: (author) => ({
      key: author.id,
      label: author.frontmatter.name,
    }),
    noDataText: 'Nenhum autor encontrado',
  }]);

  relationField.install([{
    name: 'categories',
    hook: useCategories,
    itemProps: (categories) => ({
      id: Math.random()
          .toString(36)
          .substr(2, 9),
      label: categories.fieldValue,
    }),
    sortable: true,
    multiple: true,
    noDataText: 'Nenhuma categoria encontrada',
  }]);

  relationField.install([{
    name: 'tags',
    hook: useTags,
    itemProps: (tags) => ({
      id: Math.random()
          .toString(36)
          .substr(2, 9),
      label: tags.fieldValue,
    }),
    sortable: true,
    multiple: true,
    noDataText: 'Nenhuma tag encontrada',
  }]);

//  const fileField = new TinaCMSFileField(window.tinacms);
//  fileField.install();
//  };

Notice I've used the same Math.random() formula from TinaCMS group-list example, since there's no ID attributed for categories or tags. Then, the hooks:

useAuthors.js

import { useStaticQuery, graphql } from 'gatsby'

export default () => {
  const { authors } = useStaticQuery(
    graphql`
      query authorCollectionQuery {
        authors: allMarkdownRemark(
          filter: {
            frontmatter: {
              type: {
                eq: "autor-page"
              }
            }
          }
        ) {
          nodes {
            id
            frontmatter {
              name
            }
          }
        }
      }
    `
  )

  return authors.nodes

}

useCategories.js

import { useStaticQuery, graphql } from 'gatsby'

export default () => {
  const { categories } = useStaticQuery(
    graphql`
      query categoriesCollectionQuery {
        categories: allMarkdownRemark(
          filter: {
            frontmatter: {
              type: {
                eq: "blog-post"
              }
            }
          }
        ) {
          group(field: frontmatter___categories) {
            fieldValue
          }
        }
      }
    `
  )

  return categories.group

}

useTags.js

import { useStaticQuery, graphql } from 'gatsby'

export default () => {
  const { tags } = useStaticQuery(
    graphql`
      query tagsCollectionQuery {
        tags: allMarkdownRemark(
          filter: {
            frontmatter: {
              type: {
                eq: "blog-post"
              }
            }
          }
        ) {
          group(field: frontmatter___tags) {
            fieldValue
          }
        }
      }
    `
  )

  return tags.group

}

What was expected

To be able to insert fields for these parameters into blogpost template so TinaCMS would help me handle such values

What happened

TypeError: react_is__WEBPACK_IMPORTED_MODULE_2___default.a is undefined
tinacms-fields-issue

Not a clue what is this about. Researching on Google, I found out it could be something to do with some react callback or even a version, but mine is up to date:

"react": "^16.13.1",
"react-dom": "^16.13.1",

I've pushed the repo into a branch to work only with TinaCMS and my last commit was entirely about installing tinacms-fields. You can find it here.

Could you please help me to find out what might be the issue? I'm even thinking I've installed it wrong.

@mmintel
Copy link
Owner

mmintel commented Apr 28, 2020

@edueter hi there! thanks for the issue report. I tried to investigate but it seems you didn't push any change to your branch. The fields are not installed and the gatsby-browser.js only contains

import './src/css/tailwind.css';
import './src/scss/default.scss'

@eduoliveira85
Copy link
Author

Thanks for your effort, Marc. My mistake, I thought I have done it. It's there now, with a few changes. I've uninstalled the other plugins to keep tinacms-relation-fields only, but the error keeps appearing.

This email field is something I've done yesterday to handle e-mail input for authors in my blog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants