小编Uhn*_*ney的帖子

Next.js:如何在 Next.js 中应用 Sharp lib

next/image变化太慢,所以我看到旧图像,然后出现新图像。对于这个问题,我参考如下:

Next/Image的组件出现速度太慢

通过在项目目录中运行来安装 Sharp ,然后再次yarn add sharp运行来重新启动服务器next start

他们都说我应该使用sharp.

所以我添加了sharp. 我的问题是我应该安装sharprestart server?我不需要导入sharp并执行一些代码吗?

我实际上尝试了以下方法:

import Link from 'next/link';
import Image from 'next/image';

const sharp = require('sharp');

const CustomImage = ({ src, href}) => {

  const rotateImage = () => {
    sharp(src)
  }
  
useEffect(() => {
  rotateImage()
}, [])

  return (
    <Link href={href} passHref>
        <span >
          <Image src={rotateImage}/>
        </span>
    </Link>
  );
};

export default CustomImage;
Run Code Online (Sandbox Code Playgroud)

但它给了我这个错误:

找不到模块:无法解析“child_process”

如何 …

image next.js sharp

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

image ×1

next.js ×1

sharp ×1