I'm using a Next.js template to create a personal web page to display my CS portfolio. I created a component CircularImage.js which has a circular icon of my face. When I use 'yarn dev' the image displays properly and I have no errors, but when I do 'yarn build', I get this following error:
我正在使用Next.js模板创建一个个人网页来显示我的CS投资组合。我创建了一个组件CircularImage.js,它有一个我的脸的圆形图标。当我使用‘YAR DEV’时,图像显示正确并且没有错误,但当我使用‘YAR BUILD’时,我得到以下错误:
Failed to compile.
./src/components/CircularImage/mememe.jpeg
TypeError: Failed to parse URL from /Users/jasminewang/Documents/FALL 2023/mPortfolio-main/node_modules/next/dist/server/lib/squoosh/mozjpeg/mozjpeg_node_dec.wasm
at Object.fetch (node:internal/deps/undici/undici:14152:11)
Import trace for requested module:
./src/components/CircularImage/index.tsx
./src/components/Header/index.tsx
./src/components/Layout.tsx
./src/pages/index.tsx
> Build failed because of webpack errors
error Command failed with exit code 1.
This is my image component's index.tsx, and I am SURE that the filepath is correct because the image shows up in 'yarn dev'...
这是我的图像组件的index.tsx,我确信文件路径是正确的,因为该图像显示在‘yansdev’中……
import React from "react";
import Image from "next/dist/client/image";
import image from "./mememe.jpeg";
const CircularImage = () => {
return (
<div
style={{
width: "100px",
height: "100px",
borderRadius: "50%",
overflow: "hidden",
}}
>
<Image src={image} alt="A pic of me" />
</div>
);
};
export default CircularImage;
更多回答
Have written an answer. If my answer solves your issue, please accept my answer
写了一个答案。如果我的回答解决了你的问题,请接受我的回答。
优秀答案推荐
Change your import
statement from:
将您的导入语句从:
import Image from "next/dist/client/image"
to:
致:
import Image from "next/image"
I'm assuming the above issue happened because your IDE auto-imported from the incorrect location.
我假设发生上述问题是因为您的IDE从错误的位置自动导入。
next/dist/client/image
is an internal package used by next
, and not something next
recommends doing.
Next/dist/CLIENT/IMAGE是Next使用的内部包,而不是Next推荐做的事情。
Refer for how Next.js recommends using the <Image />
component: https://nextjs.org/docs/pages/api-reference/components/image
有关Next.js建议如何使用该组件的信息,请参阅:https://nextjs.org/docs/pages/api-reference/components/image
更多回答
我是一名优秀的程序员,十分优秀!