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

Fix errors at enhanceRollupError in Vite #222

Merged
merged 1 commit into from
Oct 25, 2024
Merged

Conversation

JReinhold
Copy link
Collaborator

@JReinhold JReinhold commented Oct 24, 2024

Fixes #221

When an error is thrown during build, Vite attempts to modify the error message with error.message = "...":
https://github.com/vitejs/vite/blob/91a1acb12058d7f8ea357b7564992936eed62bc7/packages/vite/src/node/build.ts#L642

Our custom Error class didn't support that, because we add a get message() to the class. Adding a set message() too, ensures Vite doesn't thrown an error during step, so it actually is able to modify the error and throw the correct one being thrown by us.

In #221 it changes the error from:

=> Failed to build the preview
TypeError: Cannot set property message of  which has only a getter
    at enhanceRollupError (file://./node_modules/vite/dist/node/chunks/dep-BWSbWtLw.js:65318:15)
    at build (file://./node_modules/vite/dist/node/chunks/dep-BWSbWtLw.js:65456:5)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async build (./node_modules/@storybook/builder-vite/dist/index.js:58:230)
    at async Promise.all (index 0)
    at async Module.build2 (./node_modules/@storybook/builder-vite/dist/index.js:58:5160)
    at async Promise.all (index 0)
    at async buildStaticStandalone (./node_modules/@storybook/core/dist/core-server/index.cjs:46960:3)
    at async withTelemetry (./node_modules/@storybook/core/dist/core-server/index.cjs:47080:12)
    at async build (./node_modules/@storybook/core/dist/cli/bin/index.cjs:2841:3)

to the correct:

x Build failed in 1.12s
=> Failed to build the preview
[storybook:addon-svelte-csf-plugin-post] Duplicate exportNames found between two '<Story />' definitions in stories file: file://./tests/stories/test/Conflicts.stories.svelte

First instance: <Story name="First" exportName="First" ... />
Second instance: <Story name="First" exportName="First" ... />

This can happen when 'exportName' is implicitly derived by 'name'.
Complex names will be simplified to a PascalCased, valid JavaScript variable name,
eg. 'Some story name!!' will be converted to 'SomeStoryName'.
You can fix this collision by providing a unique 'exportName' prop with <Story exportName="SomeUniqueExportName" ... />.

More info: https://github.com/storybookjs/addon-svelte-csf/blob/v4.1.2/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_PLUGIN_ERROR

file: ./tests/stories/test/Conflicts.stories.svelte
SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0006 (DuplicateStoryIdentifiersError): Duplicate exportNames found between two '<Story />' definitions in stories file: file://./tests/stories/test/Conflicts.stories.svelte

First instance: <Story name="First" exportName="First" ... />
Second instance: <Story name="First" exportName="First" ... />

This can happen when 'exportName' is implicitly derived by 'name'.
Complex names will be simplified to a PascalCased, valid JavaScript variable name,
eg. 'Some story name!!' will be converted to 'SomeStoryName'.
You can fix this collision by providing a unique 'exportName' prop with <Story exportName="SomeUniqueExportName" ... />.

More info: https://github.com/storybookjs/addon-svelte-csf/blob/v4.1.2/ERRORS.md#SB_SVELTE_CSF_PARSER_ANALYSE_STORY_0006

    at getStoriesIdentifiers (./dist/parser/analyse/story/attributes/identifiers.js:56:19)
    at createAppendix (./dist/compiler/post-transform/create-appendix.js:14:30)
    at transformStoriesCode (./dist/compiler/post-transform/index.js:45:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Object.transform (./dist/compiler/plugins.js:82:13)
    at async file://./node_modules/vite-plugin-inspect/dist/index.mjs:377:17
    at async transform (file://./node_modules/rollup/dist/es/shared/node-entry.js:18676:16)
    at async ModuleLoader.addModuleSource (file://./node_modules/rollup/dist/es/shared/node-entry.js:18892:36)

Version

Published prerelease version: v5.0.0-next.8

Changelog

💥 Breaking Change

🚀 Enhancement

🐛 Bug Fix

  • Fix errors at enhanceRollupError in Vite #222 (@JReinhold)
  • refactor: Replace deprecated context="module" with module #217 (@xeho91)
  • fix(pre-transform): Move stories target component import declaration from instance to module tag #218 (@xeho91)
  • v5: Fix tags being ignored #206 (@JReinhold)
  • fix(parser): Resolve autodocs tag issue and extracting rawCode #201 (@xeho91)
  • Replace lodash usage with es-toolkit #192 (@JReinhold)
  • chore: use dist folder to load the files #185 (@benoitf)

⚠️ Pushed to next

  • fix typing issue in Example.stories.svelte (@xeho91)
  • remove obsolete test (@xeho91)

🏠 Internal

  • refactor: Improve AST-related types readability & fix existing issues #209 (@xeho91)

Authors: 4

@JReinhold JReinhold self-assigned this Oct 24, 2024
@JReinhold JReinhold added bug Something isn't working patch Increment the patch version when merged labels Oct 24, 2024
@JReinhold JReinhold marked this pull request as ready for review October 24, 2024 20:19
@JReinhold JReinhold requested a review from xeho91 October 24, 2024 20:19
Copy link
Collaborator

@xeho91 xeho91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the thorough explanation of what happened ❤️

@xeho91 xeho91 merged commit aaa2def into next Oct 25, 2024
6 of 7 checks passed
@shilman
Copy link
Member

shilman commented Oct 25, 2024

🚀 PR was released in v5.0.0-next.8 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working patch Increment the patch version when merged prerelease This change is available in a prerelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Custom errors thrown during build are being swallowed by Vite
3 participants