You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

餐厅网站开发:images.js默认导出模块需先赋值变量报错求助

解决"Assign object to a variable before exporting as module default"报错

这个报错是ESLint规则import/no-anonymous-default-export触发的,它禁止直接导出匿名对象作为模块默认导出,要求先将对象赋值给一个具名变量。

修复方案一:将对象赋值给变量后再导出

修改constants/images.js代码如下:

const images = {
  bg,
  chef,
  G,
  gallery01,
  gallery02,
  gallery03,
  gallery04,
  knife,
  logo,
  menu,
  overlaybg,
  spoon,
  welcome,
  findus,
  laurels,
  award01,
  award02,
  award03,
  award05,
  sign,
  quote,
  gericht,
};

export default images;

修复方案二:关闭对应的ESLint规则

如果不需要遵循这条规范,可以在项目的ESLint配置文件(如.eslintrc.js或.eslintrc.json)中关闭该规则:

{
  "rules": {
    "import/no-anonymous-default-export": "off"
  }
}

内容的提问来源于stack exchange,提问作者Saud Alham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 13:50:45