Skip to content

[Bug] Internal server error: Cannot add property 0, object is not extensible #327

@myieye

Description

@myieye

Describe the bug

Having a comment before the call to defineMeta() can break the story in some cases.

In that case this error is shown in the console and UI:

[vite] Internal server error: Cannot add property 0, object is not extensible
Plugin: storybook:addon-svelte-csf
File: D:/code/svelte-insertDefineMetaParameters-repro/src/stories/broken.stories.svelte
at Array.push ()
at insertDefineMetaParameters (file:///D:/code/svelte-insertDefineMetaParameters-repro/node_modules/@storybook/addon-svelte-csf/dist/compiler/post-transform/define-meta/insert-parameters.js:40:60)
at transformDefineMeta (file:///D:/code/svelte-insertDefineMetaParameters-repro/node_modules/@storybook/addon-svelte-csf/dist/compiler/post-transform/define-meta/index.js:12:5)
at transformStoriesCode (file:///D:/code/svelte-insertDefineMetaParameters-repro/node_modules/@storybook/addon-svelte-csf/dist/compiler/post-transform/index.js:35:5)
at async TransformPluginContext.transform (file:///D:/code/svelte-insertDefineMetaParameters-repro/node_modules/@storybook/addon-svelte-csf/dist/compiler/plugins.js:91:13)
at async EnvironmentPluginContainer.transform (file:///D:/code/svelte-insertDefineMetaParameters-repro/node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:31325:14)
at async loadAndTransform (file:///D:/code/svelte-insertDefineMetaParameters-repro/node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:26407:26)
at async viteTransformMiddleware (file:///D:/code/svelte-insertDefineMetaParameters-repro/node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:27492:20)

Steps to reproduce the behavior

  1. Create a new project e.g. using the steps here: https://storybook.js.org/tutorials/intro-to-storybook/svelte/en/get-started/
  2. Create a story like this:
<script module lang="ts">
  import {defineMeta} from '@storybook/addon-svelte-csf';

  /* Removing this comment fixes the story */

  const {Story} = defineMeta({
    // title: 'custom title', // uncommenting this fixes the story
  });


</script>

<Story name="Example">
  test
</Story>
  1. Navigate to the story

Expected behavior

Having comments shouldn't break the story.
Neither should not specifying a title.

Screenshots and/or logs

If applicable, add screenshots and/or logs to help explain your problem.

Environment

  • OS: Windows
  • Node.js version: 22.18.0

Additional context

As I wrote in the story code, the problem goes away if either the comment is removed or a title is specified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions