【问题标题】:Next JS: Module parse failed: Unexpected character '�' (1:0)下一个 JS:模块解析失败:意外字符 '�' (1:0)
【发布时间】:2021-03-18 17:45:48
【问题描述】:

模块解析失败:意外字符 '�' (1:0) 您可能需要适当的加载程序来处理此文件类型,目前,没有配置加载程序来处理此文件。见https://webpack.js.org/concepts#loaders (此二进制文件的源代码省略)

导入图片时出错。

有人知道为什么会这样吗?

我正在使用 nextjs

【问题讨论】:

  • 文件是否有BOM?如果可以,是否允许?
  • 不,我只是在导入图像,它会抛出错误
  • 我猜,您必须添加一些代码才能获得有用的答案...

标签: next.js


【解决方案1】:

对于有问题的人@Prabhu 的答案是正确的,但您可以像这样使用它而不提供内容。 .png 图像上的这个错误对我有用

安装:npm install next-images

在根目录 => next.config.js


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

【讨论】:

    【解决方案2】:

    在 next.config.js 中导入下一个图像

    const withImages = require('next-images')
    

    并且在 module.exports 中使用它

    module.exports = withImages({ ...//your content here })
    

    【讨论】:

    • 内容到底是什么意思?
    • 图片的放置路径?
    • module.exports = withImages({ target: '', webpack: function({...}) }) 你想为你的项目包括什么配置
    • 什么是“下一个图像”? next.config.js 是什么?可以在 webpack.config.js 中使用吗?
    • 这个工作有过吗?我不知道 module.exports = withImages({ ...//your content here }) @Prabhu 在说什么内容
    猜你喜欢
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    • 2019-08-04
    • 2019-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多