storybookjs / addon-react-native-web

Build react-native-web projects in Storybook for React
MIT License
83 stars 24 forks source link

[Bug] ReferenceError: exports is not defined since 7.6.0-alpha.5 #76

Closed adamhari closed 10 months ago

adamhari commented 11 months ago

Describe the bug

The storybook project will finish bundling, and upon visiting the web app the story window will show

ReferenceError: exports is not defined

Steps to reproduce the behavior

  1. Run storybook dev on a project >= 7.6.0-alpha.5 with addon-react-native-web.
  2. Visit the storybook app URL

https://github.com/adamhari/addon-react-native-web/tree/7.6.0-exports-is-not-defined

Expected behavior

The app will successfully render stories

Screenshots and/or logs

image

Environment

Additional context

This issue is not present in 7.6.0-alpha.4

dannyhw commented 11 months ago

I think this might relate to the removal of react as a peer dependency, will look into this.

junchenjun commented 11 months ago

Same issue here

dannyhw commented 10 months ago

Working on a fix but still struggling to find the root cause. Will update when I know more. Recommend staying on 7.5 for now if you can.

dannyhw commented 10 months ago

A fix is being worked on by the core team that will land upstream sometime soon. In the meantime this seems to be a valid workaround (put webpackFinal in main.js).


module.exports = {
  // ...
  webpackFinal: async (config) => {
    // ...

    // Remove export-order-loader since it doesn't work properly for CommonJS code
    // See https://github.com/storybookjs/storybook/issues/25383
    // TODO: remove this fix once it is fixed in the library
    config.module.rules = config.module.rules.filter(
      (rule) =>
        !rule?.use?.some?.((u) =>
          String(u?.loader)?.includes?.('export-order-loader')
        )
    );

    // ...

    return config;
  },
  // ...
};```
dannyhw commented 10 months ago

this has now been fixed in 7.6.9 and the workaround can be removed.