Core: Fix fail to load main.ts error message#26035
Conversation
main.ts over https://github.com/storybookjs/storybook/issues/23972main.ts over #23972
|
I personally haven’t ever heard the term „imperative import“ so far. I think the term „dynamic import" is far more common and is also used on docs sites like https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import or https://nodejs.org/api/esm.html#import-expressions |
|
@ndelangen People might switch to dynamic imports on the top level. And AFAIK, top-level awaits aren't supported since esbuild transforms the |
|
@valentinpalkovic yes, hence the " where they are used.`-part. When they made this change, and run into the "top level await" error, they'll know what to do? |
|
@vanessayuenn @shilman where would this config exist? The only place I can imagine would be inside a CLI flag. |
…orybookjs/storybook into norbert/handle-esm-main-error
| "ts-dedent": "^2.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "chalk": "^4.1.0", |
There was a problem hiding this comment.
could this bring potential problems for the core-events package? as chalk would be prebundled in something that goes to the browser as well
There was a problem hiding this comment.
How, could it get pre-bundled into something that goes into the browser, due to this change?
There was a problem hiding this comment.
AFAIK this doesn't have an affect on any code we ship to the browser, as long as that browser code doesn't reference chalk.
I had to move chalk into here as @vanessayuenn asked me to move this to core-events: #26035 (comment)
There was a problem hiding this comment.
Also have a funny feeling about adding chalk to that package, but I'll leave that decision to you
|
I'm ok with this workaround rather than making it configurable. However can we link show an example of a dynamic import in the error message? Do we support top level await or do they need to make async preset functions for that? |
|
@shilman do you mean like this: |
|
We do not support top-level await: We never have supported it. |
|
Yes but what's the actual replacement code for that example? Does that top level await work in main.ts? Can we actually spell it out for users? |
|
We do not support top-level await Spelling it out for users would be extremely complex. |
|
We're going to add an example of converting from static import to dynamic import.. |
…w when version is missing
|
Here's the link to the instruction to users: |
Co-authored-by: Yann Braga <yannbf@gmail.com>
| "ts-dedent": "^2.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "chalk": "^4.1.0", |
There was a problem hiding this comment.
Also have a funny feeling about adding chalk to that package, but I'll leave that decision to you
|
What's the funny feeling? What are the concerns with this? |
main.ts over #23972main.ts error useful
main.ts error usefulmain.ts error message





Closes: #23972
Closes: #25814
What I did
Catch the error in
loadMainConfig, and transform the error to be more helpful.The user was able to do something before https://github.com/storybookjs/storybook/pull/23018/files but after that change, users can have a broken
main.tsfile simply by importing (with a declarative import) a module that has nocommonjsvariant.This was an unnoticed breaking change in SB 7.1
Turning back the change is possible, but very much not preferable, because it would be a performance regression.
I hope that the message will be clear enough for users to act upon it.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
"@nuxt/kit": "3.10.1"as a dependency & installmain.ts:Before this change the command output looked like:

After this change it should look like:

Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This pull request has been released as version
0.0.0-pr-26035-sha-a321a58d. Try it out in a new sandbox by runningnpx storybook@0.0.0-pr-26035-sha-a321a58d sandboxor in an existing project withnpx storybook@0.0.0-pr-26035-sha-a321a58d upgrade.More information
0.0.0-pr-26035-sha-a321a58dnorbert/handle-esm-main-errora321a58d1708426428)To request a new release of this pull request, mention the
@storybookjs/coreteam.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=26035