-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
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
@@ -81,6 +81,7 @@ | |||
"ts-dedent": "^2.0.0" | |||
}, | |||
"devDependencies": { | |||
"chalk": "^4.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How, could it get pre-bundled into something that goes into the browser, due to this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
@@ -81,6 +81,7 @@ | |||
"ts-dedent": "^2.0.0" | |||
}, | |||
"devDependencies": { | |||
"chalk": "^4.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.ts
file simply by importing (with a declarative import) a module that has nocommonjs
variant.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:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make 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 [email protected] sandbox
or in an existing project withnpx [email protected] upgrade
.More information
0.0.0-pr-26035-sha-a321a58d
norbert/handle-esm-main-error
a321a58d
1708426428
)To request a new release of this pull request, mention the
@storybookjs/core
team.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