错误:不要使用 <img>。请改用“下一个/图像”中的图像。 - Next.js 使用 html 标签 <img /> (带样式组件)

新手上路,请多包涵

我知道在 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 许可协议

阅读 995
1 个回答

从 Next.js 11 开始, 开箱即用地支持 ESLint,现在提供了一组新规则,包括 @next/next/no-img-element 规则。

您可以在 .eslintrc 文件中禁用此特定 ESLint 规则,就像任何其他规则一样。

 {
  // ...
  "rules": {
    // Other rules
    "@next/next/no-img-element": "off"
  }
}

原文由 juliomalves 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题