question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

See original GitHub issue

My project has products so I have a subfolder in pages for example:

/pages/produkte/myproduct.js

I am using an HOC - Produkte.js. This is the root component of every product and I am passing values via props to render it.

  • Trying to set <NextSeo/> to myproduct.js changes will not apply and the title is left default.

  • Trying to set <NextSeo/> in Produkte.jsand passing props from myproduct.js will throw an error.

Invariant Violation: Element type is invalid: 
expected a string (for built-in components) or a class/function 
(for composite components) but got: undefined. 
You likely forgot to export your component from the file it's defined in, 
or you might have mixed up default and named imports.

myproduct.js

  render() {
    return (
      <Produkt
        images={ImgArray}
        headline={"TestProduct TestProduct"}
        subHeadline={"TestProduct TestProduct | TestProduct"}
        bulletPoints={BulletPoints}
        reviews={Reviews}
        price={"11,90"}
        sales={"4623"}
      >
        <NextSeo config={SeoConfig} />
        <ProductJsonLd
          productName="TestProduct"
          description={"TestProduct - TestProduct | TestProduct"}
          brand="TestProduct"
          aggregateRating={{
            ratingValue: "4.7",
            reviewCount: "215"
          }}
        />
      </Produkt>
    );
  }

EDIT: Removed <ProductJsonLd/> and can verify that the error is coming from <NextSeo/>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
n1xncommented, Jul 4, 2019

@garmeeh & @lenchik-ponchik your solutions are working.

Please consider to update the readme file. The problem was

  1. import NextSeo, { ProductJsonLd } from "next-seo";
  2. <NextSeo /> must be the very first entry in a Child Component
1reaction
garmeehcommented, Jun 25, 2019

Could you try this:

render() {
  return (
    <>
      <NextSeo config={SeoConfig} />
      <ProductJsonLd
        productName="TestProduct"
        description={"TestProduct - TestProduct | TestProduct"}
        brand="TestProduct"
        aggregateRating={{
          ratingValue: "4.7",
          reviewCount: "215"
        }}
      />
      <Produkt
        images={ImgArray}
        headline={"TestProduct TestProduct"}
        subHeadline={"TestProduct TestProduct | TestProduct"}
        bulletPoints={BulletPoints}
        reviews={Reviews}
        price={"11,90"}
        sales={"4623"}
      />
    </> 
  );
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Invariant Violation: Element type is invalid: expected a string ...
createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Read more >
(React) Element type is invalid, expected a string (for built in ...
To solve the error "Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got",...
Read more >
Element type is invalid: expected a string (for built-in ... - GitHub
The app breaks and gives this error message: Element type is invalid: expected a string (for built-in components) or a class/function (for ......
Read more >
Element type is invalid: expected a string (for ... - OneCompiler
Element type is invalid : expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Read more >
Element type is invalid: expected a string (for built-in ... - Reddit
Getting Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found