【问题标题】:Problem with import JSON in Firefox but in other browsers it work在 Firefox 中导入 JSON 时出现问题,但在其他浏览器中它可以工作
【发布时间】:2022-11-29 18:56:27
【问题描述】:

在我的新项目中,我遇到了 Firefox 的问题。首先,我想说在 Opera、Chrome 和 Edge 中它运行良好,但只有在那个浏览器中才会出现意外错误。

我对一些对象使用本地 JSON,然后在 JS 中我使用

// Import JSON Insurance Data

import insurances from './insurances.json' assert {type: 'json'}

然后

insurances.forEach(e => {myCode});

就像我告诉它的那样,它通常可以正常工作,但在控制台的 Firefox 中是这样的错误:

SyntaxError: unexpected token: identifier

浏览器指向这一行:

import insurances from './insurances.json' assert {type: 'json'}

【问题讨论】:

    标签: javascript json firefox


    【解决方案1】:

    仅通过查看 MDN 文档,Firefox 不支持导入断言。

    我也很困惑为什么它在 Opera 中为您工作,因为目前它被列为不受支持,与 Firefox 一样。

    在这里查看更多:MDN import browser compatibility

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-13
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多