我知道在 Next.js 中我们有图像组件,但我遇到的问题是我不能将它用作普通的 HTML 标记,如 <img />
。我必须给它一个布局,但是没有选项可以将它作为一个普通的 HTML 标签来控制,除此之外,我不能对它使用 framer motion。
所以我刚刚安装了 next-images
所以我当然可以导入图像并使用它们,一切正常,’直到我 npm run build the landing page 看到一些结果,并且有这个警告:
Failed to compile.
./components/Presentation/Presentation.js
77:13 Error: Do not use <img>. Use Image from 'next/image' instead. See https://nextjs.org/docs/messages/no-img-element. @next/next/no-img-element
Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
npm ERR! code ELIFECYCLE
这是我使用 img
带有样式组件的标签的地方:
<PresentationUnderText2 src="/underText-Presentation.png" alt="" />
<PresentationScissor2 src="/scissors.svg"alt=""/>
我该怎么做才能正常使用 img
标签?
原文由 Diego 发布,翻译遵循 CC BY-SA 4.0 许可协议
从 Next.js 11 开始, 开箱即用地支持 ESLint,现在提供了一组新规则,包括
@next/next/no-img-element
规则。您可以在
.eslintrc
文件中禁用此特定 ESLint 规则,就像任何其他规则一样。