reactjs 使用Astro框架构建错误& react-image-gallery

fdx2calv  于 2023-04-29  发布在  React
关注(0)|答案(1)|浏览(101)

我正在使用"astro": "~2.3.0""@astrojs/react": "~2.1.1"(使用"react": "~18.2.0""react-dom": "~18.2.0")& "react-image-gallery": "~1.2.11",当我尝试构建(使用astro build)astro应用程序时,我从ImageGallery组件得到这个错误:

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

而且似乎在某些导入上有错误💭
导致错误的组件是:

import React from "react";
import ImageGallery from "react-image-gallery";
import "react-image-gallery/styles/scss/image-gallery.scss";
import styles from "./styles.module.scss";

function ProjectPage({ project = {} }) {
  return (
    <div className={styles.project}>
      <ImageGallery
        items={project.images}
      />
    </div>
  );
}
export default ProjectPage;

我在另一个astro文件中使用了client:load指令:

<ProjectView project={selectedProject} client:load />

问题出现在prod build上,而在dev server上运行时不是。有人知道为什么会这样吗??

p3rjfoxz

p3rjfoxz1#

看起来这是一个prod构建错误,解决方法是:

import Gallery from "react-image-gallery";
const ImageGallery = (Gallery as any).default ?? Gallery;

Gitgub问题解答

相关问题