Skip to content

TypeError: import_meta.resolve is not a function when starting Storybook React Native with Node.js v22.21.1 #819

@forimbajosh21

Description

@forimbajosh21

Describe the bug
Hi! I'm trying to integrate Storybook into my React Native project, but it fails to start with TypeError: import_meta.resolve is not a function error during main configuration file evaluation.
Btw, I'm using Expo without expo-router.

To Reproduce
Steps to reproduce the behavior:

  1. Set up React Native Expo project with Storybook
  2. Configure main.ts with standard TypeScript configuration
  3. Run yarn storybook command
  4. See error during startup process with MainFileEvaluationError

Expected behavior
Storybook should successfully start and load the configuration from main.ts, launching the development server to view component stories in React Native environment.

Screenshots
N/A - Terminal error output provided below.

Code snippets
Current metro.config.js configuration:

// Learn more https://docs.expo.io/guides/customizing-metro
const {getDefaultConfig} = require('expo/metro-config');
const {withStorybook} = require('@storybook/react-native/metro/withStorybook');
const path = require('path');

/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);
const {transformer, resolver} = config;

config.transformer = {
  ...transformer,
  babelTransformerPath: require.resolve('react-native-svg-transformer/expo'),
};
config.resolver = {
  ...resolver,
  assetExts: resolver.assetExts.filter(ext => ext !== 'svg'),
  sourceExts: [...resolver.sourceExts, 'svg'],
  nodeModulesPaths: [
    ...resolver.nodeModulesPaths,
    path.resolve(__dirname, 'modules'),
  ],
  extraNodeModules: {
    src: path.resolve(__dirname, 'src'),
    app: path.resolve(__dirname, 'src/app'),
    common: path.resolve(__dirname, 'src/common'),
    features: path.resolve(__dirname, 'src/features'),
    navigations: path.resolve(__dirname, 'src/navigations'),
    services: path.resolve(__dirname, 'src/services'),
  },
};

module.exports = withStorybook(config, {
  enabled: process.env.EXPO_PUBLIC_STORYBOOK_ENABLED === 'true',
});

Current main.ts configuration:

import type {StorybookConfig} from '@storybook/react-native';

const main: StorybookConfig = {
  stories: [
    // the paths are relative to the main.ts file itself
    '../src/features/shared/components/**/*.stories.?(ts|tsx|js|jsx)',
  ],
  addons: [
    '@storybook/addon-ondevice-controls',
    '@storybook/addon-ondevice-actions',
  ],
};

export default main;

Complete error trace:

SB_CORE-SERVER_0007 (MainFileEvaluationError): Storybook couldn't evaluate your .rnstorybook/main.ts file.

Original error:
TypeError: import_meta.resolve is not a function
    at importMetaResolve (/node_modules/storybook/dist/_node-chunks/chunk-Q6B5LJGA.js:4:21511)
    at importModule (/node_modules/storybook/dist/_node-chunks/chunk-Q6B5LJGA.js:4:22072)
    at loadMainConfig (node_modules/storybook/dist/_node-chunks/chunk-QZJSO2TW.js:25:7618)
    at generate2 (node_modules/@storybook/react-native/dist/metro/withStorybook.js:133:20)
    at loadMainConfig (node_modules/storybook/dist/_node-chunks/chunk-QZJSO2TW.js:35:156)
    at generate2 (node_modules/@storybook/react-native/dist/metro/withStorybook.js:133:20) {
  data: {
    location: '.rnstorybook/main.ts',
    error: TypeError: import_meta.resolve is not a function
        at importMetaResolve (node_modules/storybook/dist/_node-chunks/chunk-Q6B5LJGA.js:4:21511)
        at importModule (node_modules/storybook/dist/_node-chunks/chunk-Q6B5LJGA.js:4:22072)
        at loadMainConfig (node_modules/storybook/dist/_node-chunks/chunk-QZJSO2TW.js:25:7618)
        at generate2 (node_modules/@storybook/react-native/dist/metro/withStorybook.js:133:20)
  },
  fromStorybook: true,
  isHandledError: false,
  category: 'CORE-SERVER',
  documentation: false,
  code: 7,
  _name: 'MainFileEvaluationError'
}

System:

  • Node.js: v22.21.1
  • Storybook: 10.1.3
  • React Native: Expo SDK 53, React-Navigation 6
  • Platform: macOS
  • Package Manager: Yarn

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions