storybook: [Bug]: [storybook:mdx-plugin] Unexpected `FunctionDeclaration` in code: only import/exports are supported

Describe the bug

Hi, after upgrade from Storybook 7.4.6 to 7.5.1 out build started to fail with the message

[storybook:mdx-plugin] Unexpected `FunctionDeclaration` in code: only import/exports are supported
file: /Users/tomas.litera/Work/lmc/spirit-design-system/packages/web-react/docs/stories/Styling.stories.mdx
=> Failed to build the preview
6:1-58:2: Unexpected `FunctionDeclaration` in code: only import/exports are supported

I have tried to find the specific version where the problem is and it seems that this started with v7.5.0. I have also checked the documentation and tried to find out if I need to configure something more but I found nothing.

So I would be happy for any help with this issue πŸ˜ƒ Thanks

To Reproduce

main.ts

import type { StorybookViteConfig } from '@storybook/builder-vite';
import { dirname, join, resolve } from 'path';
import { mergeConfig } from 'vite';
import markdownRawPlugin from 'vite-raw-plugin';

const config: StorybookViteConfig = {
  stories: ['../packages/**/*.stories.mdx', '../packages/**/*.stories.@(ts|tsx)',],

  addons: [
    getAbsolutePath('@storybook/addon-links'),
    getAbsolutePath('@storybook/addon-docs'),
    getAbsolutePath('@storybook/addon-essentials'),
  ],

  features: {
    storyStoreV7: true,
  },

  core: {
    disableTelemetry: true,
  },

  async viteFinal(config) {
    // Merge custom configuration into the default config
    return mergeConfig(config, {
      plugins: [
        markdownRawPlugin({
          fileRegex: /\.md$/,
        }),
      ],
      css: {
        postcss: resolve(__dirname, 'config'),
        preprocessorOptions: {
          scss: {
            includePaths: [
              resolve(__dirname, '../node_modules'),
              resolve(__dirname, '../node_modules/@lmc-eu/spirit-design-tokens/src/scss'),
            ],
          },
        },
      },
    });
  },

  framework: {
    name: getAbsolutePath('@storybook/react-vite'),
    options: {},
  },

  docs: {
    autodocs: true,
    defaultName: 'Overview',
  },
};

export default config;

function getAbsolutePath(value: string): any {
  return dirname(require.resolve(join(value, 'package.json')));
}

Styling.stories.mdx

import { Meta } from '@storybook/blocks';

<Meta title="Introduction/Styling" />

# Styling

This page describes how styling works in Spirit Web React, including how to customize spacing, sizing, and positioning,
and how to create your own custom components using Spirit styles.

## Introduction

Spirit components are designed to be consistent across all LMC applications. They include built-in styling that has been
considered carefully, and extensively tested. In general, customizing Spirit design is discouraged, but most components
do offer control over layout and other aspects. In addition, you can use Spirit defined design tokens to ensure your
application conforms to design requirements, and is adaptive across platform scales and color schemes.

## Style props

**Will be implemented soon**

All Spirit Web React components support a limited set of styling options, including layout, spacing, sizing, and
positioning options. While internal component styles such as padding, colors, borders and text styles are included
in Spirit and not available to override, external styles like margins and sizes can be set on all components.

Supported styling options are available as props on every Spirit Web React component.

**Will be implemented soon**

## Escape hatches

While we encourage teams to utilize Spirit design as it is, we do realize that sometimes product specific customizations
may be needed. In these cases, we encourage you or your designers to **talk to us**. We may be able to suggest
an alternative implementation strategy, or perhaps your design can help inform future Spirit additions.

While the traditional className and style props are not supported in Spirit Web React components, there are two escape
hatches that you can **use at your own risk**. These are UNSAFE_className and UNSAFE_style. Use of these props should be
considered **a last resort**. They can be used to work around bugs or limitations in Spirit Web React, but should
not be used in the long term.

The reasoning behind this is that future updates to Spirit design may cause unintended breaking changes in products.
If the internal DOM structure or CSS properties of a Spirit Web React component change, this may lead to conflicts
with CSS overrides in products. For this reason, className and style are unsafe, and if you use them know that you
are doing so at your own risk.

System

Storybook Environment Info:

  System:
    OS: macOS 13.6
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.20.2 - ~/.nvm/versions/node/v16.20.2/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn <----- active
    npm: 8.19.4 - ~/.nvm/versions/node/v16.20.2/bin/npm
    pnpm: 8.1.1 - ~/.local/share/pnpm/pnpm
  Browsers:
    Chrome: 118.0.5993.88
    Edge: 117.0.2045.55
    Safari: 16.6
  npmPackages:
    @storybook/addon-actions: 7.5.0 => 7.5.0 
    @storybook/addon-docs: 7.5.0 => 7.5.0 
    @storybook/addon-essentials: 7.5.0 => 7.5.0 
    @storybook/addon-links: 7.5.0 => 7.5.0 
    @storybook/addons: 7.5.0 => 7.5.0 
    @storybook/blocks: 7.5.0 => 7.5.0 
    @storybook/client-api: 7.5.0 => 7.5.0 
    @storybook/html: 7.5.0 => 7.5.0 
    @storybook/react: 7.5.0 => 7.5.0 
    @storybook/react-vite: 7.5.0 => 7.5.0 
    @storybook/theming: 7.5.0 => 7.5.0 
    eslint-plugin-storybook: 0.6.15 => 0.6.15 
    storybook: 7.5.0 => 7.5.0

Additional context

Problems started after merge of our PR (https://github.com/lmc-eu/spirit-design-system/pull/1105).

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 16 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I ran into this error today after upgrading to Storybook 8. I tried a number of things to resolve, but ultimately the issue was I had both @storybook/addon-essentials and @storybook/addon-docs specified in my main.ts file. Once I removed the addon-docs (since its already in the essentials package), everything worked fine for me.

Same issue here, but suggested solution didnt helped.

Can it be related if to use reactDocgen or alternative?

I ran into this error today after upgrading to Storybook 8. I tried a number of things to resolve, but ultimately the issue was I had both @storybook/addon-essentials and @storybook/addon-docs specified in my main.ts file. Once I removed the addon-docs (since its already in the essentials package), everything worked fine for me.

@dcneiner Problem solved βœ… Thanks a lot! πŸ˜ƒ

Just removed the addon-docs in my v7 πŸ˜ƒ

I ran into this error today after upgrading to Storybook 8. I tried a number of things to resolve, but ultimately the issue was I had both @storybook/addon-essentials and @storybook/addon-docs specified in my main.ts file. Once I removed the addon-docs (since its already in the essentials package), everything worked fine for me.

Legend!

We are running into this on Storybook 8 (8.0.5 to be exact). Can’t render basic MDX… it has to be some basic misconfiguration or missing peer package.

We are using PNPM if that is relevant. Was anyone able to solve this? We have already removed the duplicate addon-docs module and even removed the addon-docs dependency from package.json, with no success

We are also facing this problem. Except we are currently using storybook 7.5.3 and it is working. If i update to a newer Version of Storybook like < 7.6.0 we also get the Unexpected FunctionDeclaration in code: only import/exports are supported.