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

Error when importing to a custom block in WordPress block editor #791

Open
matthewmcvickar opened this issue Mar 11, 2024 · 0 comments
Open

Comments

@matthewmcvickar
Copy link

matthewmcvickar commented Mar 11, 2024

Describe the bug

When importing this project to use in a custom block in the WordPress block editor, the component does not work and instead shows a bunch of errors:

image
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.

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

I have a workaround for this (see below).

Image Gallery Version

1.3.0

To Reproduce

  1. Run WordPress locally.
  2. Use the @wordpress/create-block package to scaffold a custom block.
  3. In your custom block, add this react-image-gallery component as a dependency.
  4. Import the package as directed: import ImageGallery from 'react-image-gallery';
  5. Include the example code from the repo homepage in the JSX for editing your custom block.
  6. In the block editor, notice the custom block will not render and that there are errors in the browser console.

Expected behavior

The react-image-gallery component should import and render without error.

Client info (please complete the following information):

  • OS: macOS
  • Browser: latest versions of Firefox, Chrome, and Safari

Additional context

I am running Node v20 and NPM v10, and set "type": "module" in package.json so the project is fully ESM.

By searching around, I found a workaround that works in #727. I changed my code:

// doesn't work:
import ImageGallery from 'react-image-gallery';
// does work:
import Gallery from 'react-image-gallery';
const ImageGallery = Gallery.default ? Gallery.default : Gallery;

I don't understand why this workaround works, and it seems like it shouldn't be necessary.

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

1 participant