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
Support ESModule #9854
Comments
Main.js runs during the bootstrap of Storybook it's not something that is bundled with webpack. So if you want to use mjs, you need your node to understand ESM |
@igor-dv as indicated I am using Node v13.6.0 which has out-of-box support for ESM. I already have a bunch of other Node CLI scripts in ESM format and they are all working. |
Keep in mind for ESM, name of the script will end in |
Tried this and didn't work as well: export const stories = ["../src/**/*.stories.js"];
export default { stories }; So in both cases (this and the original comment) instead of going to http://localhost:9009/?path=/story/welcome--to-storybook, I ended up with http://localhost:9009/?path=/story/* in an apparently stuck state. |
@shilman @igor-dv my guess is adding |
@gsklee that sounds reasonable. Any chance you can get a dev setup on your local machine, test it out, and provide a PR if it works? |
@gsklee, sorry, missed your node version. you can probably add
require for mjs though.. this is something that should be checked 🤔
|
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
cc @yannbf |
Hey @gsklee, what @igor-dv said is correct. The However, that is not optimal for your project, given that every time you run npm or yarn install it will override that change. Also, I believe right now storybook only supports My suggestion to you is to try the following: |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
A much simpler way to solve ES Module issues is to not use Node, and instead use the "esm" module (from the creator of Lodash). With that module and Node's
It seems to me the ideal solution here would be to just give the storybook command a EDIT Actually, while the above would be nice to have, here's a simple workaround for anyone who wants to use ES Modules with Storybook. Simply
Then just move whatever you used to have in |
Ooh-la-la!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.0-alpha.31 containing PR #10097 that references this issue. Upgrade today to try it out! You can find this prerelease on the Closing this issue. Please re-open if you think there's still more to do. |
Did we had a revert on this fix? It is not recognizing my "main.mjs"... And while we are at it, why not validate the package.json type use the appropriate loader now that all stable versions of node support ESM? Then just always try to get the "main.js" |
Wanted to poke @shilman here, considering we don't have the ability to reopen this issue. Running into the same issue as @kevinfaveri. |
Cc @yannbf can you take a look? |
+1 I'm having the same issue!!! |
Same issue... |
I'm trying to use Things I've tried:
|
@aendra-rininsland There is this new kid on the block called ladle. worth checking if they support esm. |
Can you try updating to the 6.5.0 beta? I have been running my storybook with type: module for the last year with a |
What full support includes? Creating a build for production with 6.5.0 beta is still broken (with main.cjs + Webpack 5 + type: module). |
I wasn't aware of that issue, thanks @Merri. I don't use webpack, but it would be awesome if someone could dig into this and find out why that error is happening, and how to fix it. |
@JustFly1984 That's not really an appropriate solution to this; even if I wanted to fully change out the infrastructure (I really don't), Ladle doesn't support the .mdx stories my library is written in. |
@aendra-rininsland i tend to ignore “just use an entirely different product to solve this one use case” advice. |
Yeah i feel like storybook should have a solution to this. rather than just saying use something else. |
@The-Code-Monkey the core storybook team is really quite small. If you're able to dig in and help to make a solution to provide better support for esmodules, it would be greatly appreciated! |
@IanVS I'm willing to have a look into it, could you possibly point me in the direction of where the main.js file gets loaded normally. |
Awesome! The main file is referenced and loaded in a number of different places, including presets, plugins, and frameworks. Searching for |
I've actually found the solution is to name the main.js file main.cjs and storybook then handles it correctly |
Still not working for me neither, I have the builder-vite, my config in TypeScript and my project in ESM and I cannot start storybook. Whatever I do I run into a babel regenerator esm import stuff that storybook dont like.
|
Zoinks!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-alpha.16 containing PR #18648 that references this issue. Upgrade today to the
Closing this issue. Please re-open if you think there's still more to do. |
ZOMG!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.10-alpha.0 containing PR #18648 that references this issue. Upgrade today to the
|
EDIT: Fixed this! I enabled babelModeV7, added a {
"presets": [["@babel/preset-env", {
"modules": "cjs"
}],"@babel/preset-typescript"]
} and renamed the file to Note that, I'm using the current stable version with this setup, that is Original issue: Did someone get it working with the pre-release version? It still fails for me. In my new Vue 3 + Vite project, tried:
which failed as it had some issues with the framework. Logs for that if it helps:
So I tried:
Which installed v6.15.10-alpha.0 and created I tried renaming import type {StorybookViteConfig} from '@storybook/builder-vite' which fails with:
I tried removing
I tried renaming it to Note that, my top-level |
Jiminy cricket!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.10 containing PR #18648 that references this issue. Upgrade today to the
|
Hey peeps! This ☝️ release does not add support for ESM but rather adds a small workaround for CLI starters. If you are looking into having actual ESM support, Storybook v7.0.0-alpha.12 does support it. |
I have a limited work-around to import an ESM dependency from the storybook config (CJS, typescript) while waiting on first-class support from storybook. This should work if your node version is new enough to support async Using /**
* Use to import deps that are ESM-only. We need to use dynamic/async `import()` to load ESM packages.
* However, the ts-node embedded in storybook can't disambiguate this case from other imports (and it only works in "moduleResolution":
* "nodenext") and compiles it to a sync `require` call.
*
* So, use this work-around to preserve the native `import()` method by tricking typescript with an eval.
*
* @nb This can be removed if storybook starts supporting ESM for its config: https://github.com/storybookjs/storybook/issues/9854
*
* @see https://github.com/microsoft/TypeScript/issues/43329#issuecomment-811606238
*/
const dynamicImport = new Function('modulePath', 'return import(modulePath)'); And then use that method to import the ESM dependencies. Don't forget to |
@kmannislands Storybook 7 includes first-class support for ESM config files! |
I tried changing
.storybook/main.js
to.storybook/main.mjs
and its content to:This does not seem to work or is something supported as a
$ yarn storybook
command would bring up a broken Storybook interface.Node version is v13.6.0.
The text was updated successfully, but these errors were encountered: