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

[Bug]: SyntaxError: Unexpected token '<', Storybook Core Server doesn't know how to process Svelte files #189

Open
arkmech opened this issue Jul 13, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@arkmech
Copy link

arkmech commented Jul 13, 2024

Describe the bug

In main.ts, adding @storybook/addon-svelte-csf to the addons array. Storybook exists. When removing the @storybook/addon-svelte-csf, storybook server starts ok.

It doesn't recognize the < from the Svelte components (Meta) <script> tag form the node modules.

  1. Something wrong from main.ts
    SB_CORE-SERVER_0002 (CriticalPresetLoadError): Storybook failed to load the following preset: ./.storybook/main.ts.

  2. Coming from this addon.
    SB_CORE-SERVER_0002 (CriticalPresetLoadError): Storybook failed to load the following preset: /Users/me/Dev/project/node_modules/@storybook/addon-svelte-csf/dist/index.js.

  3. Specifically the < from the script tag.

/Users/me/Dev/project/node_modules/@storybook/addon-svelte-csf/dist/components/Meta.svelte:1
<script>
^

My .main.ts

const config: StorybookConfig = {
  stories: ["../src/lib/**/*.mdx", "../src/lib/**/*.stories.@(js|jsx|mjs|ts|tsx|svelte)"],
  addons: [
    getAbsolutePath("@storybook/addon-links"),
    getAbsolutePath("@storybook/addon-essentials"),
    getAbsolutePath("@chromatic-com/storybook"),
    getAbsolutePath("@storybook/addon-interactions"),
    getAbsolutePath("@storybook/addon-svelte-csf"),
  ],
  framework: {
    name: getAbsolutePath("@storybook/sveltekit"),
    options: {},
  },
};
export default config;

Steps to reproduce the behavior

  1. Make a Turborepo project
  2. The UI library is a SvelteKit Library Project
  3. Initialize storybook
  4. Add the @storybook/addon-svelte-csf to the addons array and .stories.svelte to the stories array

Expected behavior

Storybook Server to properly load the @storybook/addon-svelte-csf addon and be able to write stories in Svelte CSF, aka Button.stories.svelte

Environment

  • OS: MacOS Sonoma
  • Node.js version: v22.4.1
  • NPM version: 10.8.1
  • Browser (if applicable): Chrome
  • Browser version (if applicable): Version 126.0.6478.127 (Official Build) (arm64)
  • Device (if applicable): Macbook Pro M1 Max
@arkmech arkmech added the bug Something isn't working label Jul 13, 2024
@JReinhold
Copy link
Collaborator

Could you try removing the getAbsolutePath call from the svelte addon, and just have the plain string?

@arkmech
Copy link
Author

arkmech commented Jul 13, 2024

It came when I setup Storybook, since I use pnpm and turborepo.

In, main.ts

/**
 * This function is used to resolve the absolute path of a package.
 * It is needed in projects that use Yarn PnP or are set up within a monorepo.
 */
function getAbsolutePath(value: string): any {
  return dirname(require.resolve(join(value, "package.json")));
}

@arkmech
Copy link
Author

arkmech commented Jul 13, 2024

Could you try removing the getAbsolutePath call from the svelte addon, and just have the plain string?

If I do remove it, then yeah storybook starts up. But thats because its no longer referencing the package in node_modules. But the *.stories.svelte is causing the issue after that.

@JReinhold
Copy link
Collaborator

Okay.

Please share a minimal reproduction repo that we can investigate.

See https://storybook.js.org/docs/contribute/how-to-reproduce

@arkmech
Copy link
Author

arkmech commented Jul 15, 2024

Yeah I'm actually thinking this is a Svelte 5 compatibility issue, I think I will just wait till Svelte 5 is released and Storybook has full support for Svelte 5. Thanks

@JReinhold
Copy link
Collaborator

Yeah I'm actually thinking this is a Svelte 5 compatibility issue, I think I will just wait till Svelte 5 is released and Storybook has full support for Svelte 5. Thanks

We just released support for Svelte 5 in a prerelease, maybe that helps you. See #191

You can try it out with npm install @srorybook/addon-svelte-csf@next

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

2 participants