【问题标题】:TypeError: Cannot assign to read only property 'exports' of object '#<Object>'TypeError:无法分配给对象“#<Object>”的只读属性“exports”
【发布时间】:2021-09-26 01:50:19
【问题描述】:

我正在尝试通过 Expo 运行 React Native Web。

我不断收到错误:

TypeError: Cannot assign to read only property 'exports' of object '#<Object>'

据我所知,这是由于某些模块导出问题。

我已经创建了一个像这样的 babel.config.js:

module.exports = function (api) {
  api.cache(true);
  return {
    "presets": [
      ["babel-preset-expo", {
      "web": {
        "disableImportExportTransform": true
      }
    }]
    ]
  };
};

这与https://www.npmjs.com/package/babel-preset-expo 的建议相似

但是,我仍然收到此错误。

我该如何解决这个问题?我让 React Native Web 在另一台计算机上运行,​​但暂时不得不移动计算机,我在配置它以使其再次运行时遇到了很多麻烦。

如果有帮助,它似乎与我正在使用的特定模块有关:

E:/MyProjectOfficial/Frontend/MyProjectFrontendExpo/node_modules/react-native-calendars/src/dateutils.js:145

> 145 | module.exports = {
  146 |   weekDayNames,
  147 |   sameMonth,
  148 |   sameWeek,

【问题讨论】:

    标签: javascript react-native npm expo babeljs


    【解决方案1】:

    你可以这样试试:

    module.exports = {
      presets: [
     [
      'babel-preset-expo',
      {
        web: { disableImportExportTransform: false }
         },
       ],
      ],
       };
    

    今天晚上我遇到了同样的问题,我使用与您相同的文章修复了它。关键是将babel.config.ja 中的选项设置为false 而不是true。这对我有用,我希望它也可以帮助你。

    【讨论】:

      猜你喜欢
      • 2019-11-28
      • 2019-04-27
      • 2019-06-13
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-08
      • 2021-01-08
      相关资源
      最近更新 更多