如何在nextjs / react

时间:2020-06-13 18:47:13

标签: reactjs sass next.js next-images

我正在尝试映射图像数组并在nextjs应用中渲染。

  const style = {
    backgroundImage: `url("${require(`/${post.images}`)}")`,
  };

我收到此错误消息:

./public/tech1.jpg 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

./public/tech2.jpg 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

./public/tech3.jpg 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

next.config.js

const withImages = require("next-images");
module.exports = withImages();

我可以渲染图像,但不能动态渲染,就像这样:

 backgroundImage: `url("${require(`/tech2.jpg`)}")`,

请问该如何解决?

0 个答案:

没有答案