Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V8 migration issue #614

Open
mzaien opened this issue Oct 9, 2024 · 8 comments
Open

V8 migration issue #614

mzaien opened this issue Oct 9, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@mzaien
Copy link

mzaien commented Oct 9, 2024

Describe the bug
After upgrading to storybook v8 and updating metro + running storybook-generate the app did not work I got this error
The package at "node_modules/axios/dist/node/axios.cjs" attempted to import the Node standard library module "url". It failed because the native React runtime does not include the Node standard library.

To Reproduce
Steps to reproduce the behavior:

  1. upgrade to v8
  2. run storybook-generate
  3. update metro
  4. run yarn storybook EXPO_PUBLIC_STORYBOOK_ENABLED='true' expo start --dev-client

Expected behavior
our storybook project opens in the simolator

Screenshots
Image

Code snippets

old metro config

const {getSentryExpoConfig} = require('@sentry/react-native/metro');

const defaultConfig = getSentryExpoConfig(__dirname);
defaultConfig.resolver.resolveRequest = (context, moduleName, platform) => {
    const defaultResolveResult = context.resolveRequest(
        context,
        moduleName,
        platform,
    );

    if (
        (process.env.EXPO_PUBLIC_STORYBOOK_ENABLED !== 'true' &&
            defaultResolveResult?.filePath?.includes?.('.storybook/')) ||
        defaultResolveResult?.filePath?.includes?.('*.stories.tsx')
    ) {
        return {
            type: 'empty',
        };
    }

    return defaultResolveResult;
};

module.exports = defaultConfig;

new metro config

const {getSentryExpoConfig} = require('@sentry/react-native/metro');
const path = require('path');
const withStorybook = require('@storybook/react-native/metro/withStorybook');

const defaultConfig = getSentryExpoConfig(__dirname);

module.exports = withStorybook(defaultConfig, {
    // Use a proper condition to enable Storybook only when the env variable is set to 'true'
    enabled: process.env.EXPO_PUBLIC_STORYBOOK_ENABLED === 'true',
    // Make sure the config path points to the correct Storybook folder
    configPath: path.resolve(__dirname, './.storybook'),
});

System:
Please paste the results of npx -p @storybook/cli@next sb info here.
sh: @storybook/[email protected]: No such file or directory
Image

Additional context
I only have this storybook deps

    "@storybook/addon-ondevice-actions": "^8.3.5",
    "@storybook/addon-ondevice-controls": "^8.3.5",
    "@storybook/react": "^8.3.5",
    "@storybook/react-native": "^8.3.5",
@AdamTyler
Copy link

I got by this specific error by using:

config.resolver.unstable_conditionNames: ['browser', 'require', 'react-native'],

in my metro.config.js.

Unfortunately I'm now running into this issue:

Image

@mzaien
Copy link
Author

mzaien commented Oct 9, 2024

Hey @AdamTyler I did what you have provided and added the babel plugin (as a dev dependancies) and things worked 🚀

@shilman shilman added the bug Something isn't working label Oct 9, 2024
@dannyhw
Copy link
Member

dannyhw commented Oct 9, 2024

@AdamTyler does adding the babel plugin in the error message resolve the issue you are having?

@AdamTyler
Copy link

AdamTyler commented Oct 14, 2024

@mzaien @dannyhw adding the babel plugin did take care of it!

I originally tried adding it with yarn but forgot to include it in the babel.config

running storybook now is working for me but running my app non storybook gives me this error:

Image

I'm assuming its something to do with my metro.config

@dannyhw
Copy link
Member

dannyhw commented Oct 14, 2024

In some of my examples I had config that would return an empty module for storybook when its not being used, maybe if you remove that it would fix this issue. Or maybe adding defaultResolveResult?.filePath?.includes?.("@storybook")

This type of stuff:

defaultConfig.resolver.resolveRequest = (context, moduleName, platform) => {
  const defaultResolveResult = context.resolveRequest(
    context,
    moduleName,
    platform
  );

  if (
    process.env.STORYBOOK_ENABLED !== "true" &&
    defaultResolveResult?.filePath?.includes?.(".ondevice/")
  ) {
    return {
      type: "empty",
    };
  }

  return defaultResolveResult;
};

@AdamTyler
Copy link

AdamTyler commented Oct 14, 2024

I had a few of those that I commented out. Let me add my current config to make this easier (you can see commented out parts from v7 config). Let me know if anything jumps out at you:

const { getSentryExpoConfig } = require('@sentry/react-native/metro');
const withStorybook = require('@storybook/react-native/metro/withStorybook');
// const { generate } = require('@storybook/react-native/scripts/generate');
const path = require('path');

// Generate the story loader
// if (process.env.EXPO_PUBLIC_STORYBOOK_ENABLED === 'true') {
//   generate({
//     configPath: path.resolve(__dirname, './.storybook'),
//   });
// }

module.exports = (() => {
  const config = getSentryExpoConfig(__dirname);
  const { resolver } = config;

  config.transformer = {
    ...config.transformer,
    babelTransformerPath: require.resolve('react-native-svg-transformer/expo'),
    unstable_allowRequireContext: true,
  };

  config.resolver = {
    ...config.resolver,
    assetExts: resolver.assetExts.filter((ext) => ext !== 'svg'),
    resolveRequest: (context, moduleName, platform) => {
      // if (
      //   moduleName === '@storybook/test' ||
      //   moduleName.endsWith('.css')
      // ) {
      //   return { type: 'empty' };
      // }

      const defaultResolveResult = context.resolveRequest(
        context,
        moduleName,
        platform,
      );

      // if (
      //   process.env.EXPO_PUBLIC_STORYBOOK_ENABLED !== 'true' &&
      //   defaultResolveResult?.filePath?.includes?.('.storybook/')
      // ) {
      //   return { type: 'empty' };
      // }

      return defaultResolveResult;
    },
    sourceExts: [...resolver.sourceExts, 'svg'],
    unstable_conditionNames: ['browser', 'require', 'react-native'],
  };

  return withStorybook(config, {
    configPath: path.resolve(__dirname, './.storybook'),
    enabled: process.env.EXPO_PUBLIC_STORYBOOK_ENABLED === 'true',
  });
})();

I thought maybe it was from using getSentryExpoConfig but I swapped that with getDefaultConfig and saw the same error

@dannyhw
Copy link
Member

dannyhw commented Oct 14, 2024

Hmm I guess you may just need package exports enabled

unstable_enablePackageExports

its also added by withStorybook when enabled is true

@AdamTyler
Copy link

Hmm I guess you may just need package exports enabled

unstable_enablePackageExports

its also added by withStorybook when enabled is true

This fixed it! Thanks @dannyhw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants