storybook: framework-preset-vue requires `babel-preset-vue` but does not depend on it

Bug or support request summary

When using SB in a vue app, this line runs:

https://github.com/storybooks/storybook/blob/71be40518b0e42e93ad37dc4669d10dc2a1d4159/app/vue/src/server/framework-preset-vue.js#L32

I’m not sure if it should even be running that line, as this project has a babel.config.js which contains:

module.exports = {
  presets: ["@vue/app"]
};

Steps to reproduce

npx -p @vue/cli vue create --preset hichroma/vue-preset-learnstorybook taskbox
cd taskbox

npx -p @storybook/cli@rc sb init
yarn storybook

You’ll see:

ERR! Error: Cannot find module 'babel-preset-vue'
ERR!     at Function.Module._resolveFilename (module.js:547:15)
ERR!     at Function.resolve (internal/module.js:18:19)
ERR!     at Object.babelDefault (/private/tmp/taskbox/node_modules/@storybook/vue/dist/server/framework-preset-vue.js:38:79)
ERR!     at /private/tmp/taskbox/node_modules/@storybook/core/dist/server/presets.js:73:26
ERR!     at Array.reduce (<anonymous>)
ERR!     at applyPresets (/private/tmp/taskbox/node_modules/@storybook/core/dist/server/presets.js:66:18)
ERR!     at Object.apply (/private/tmp/taskbox/node_modules/@storybook/core/dist/server/presets.js:84:14)
ERR!     at /private/tmp/taskbox/node_modules/@storybook/core/dist/server/core-preset-dev.js:37:20
ERR!     at _default (/private/tmp/taskbox/node_modules/@storybook/core/dist/server/loadCustomBabelConfig.js:88:29)
ERR!     at Object.babel (/private/tmp/taskbox/node_modules/@storybook/core/dist/server/core-preset-dev.js:36:45)
ERR!     at /private/tmp/taskbox/node_modules/@storybook/core/dist/server/presets.js:73:26
ERR!     at Array.reduce (<anonymous>)
ERR!     at applyPresets (/private/tmp/taskbox/node_modules/@storybook/core/dist/server/presets.js:66:18)
ERR!     at Object.apply (/private/tmp/taskbox/node_modules/@storybook/core/dist/server/presets.js:84:14)
ERR!     at Object.babel (/private/tmp/taskbox/node_modules/@storybook/core/dist/server/config.js:27:22)
ERR!     at getWebpackConfig (/private/tmp/taskbox/node_modules/@storybook/core/dist/server/config.js:55:30)

babel-preset-vue is not a (peer) dependency of @storybook/vue, and I don’t think it should be being used at all.

Please specify which version of Storybook and optionally any affected addons that you’re running

Affected platforms

Dependencies of app:

"dependencies": {
    "vue": "^2.5.17"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.0.5",
    "@vue/cli-plugin-eslint": "^3.0.5",
    "@vue/cli-plugin-unit-jest": "^3.0.5",
    "@vue/cli-service": "^3.0.5",
    "@vue/eslint-config-prettier": "^3.0.5",
    "@vue/test-utils": "^1.0.0-beta.20",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "^23.0.1",
    "vue-template-compiler": "^2.5.17",
    "@storybook/vue": "^4.0.0-rc.0",
    "@storybook/addon-actions": "^4.0.0-rc.0",
    "@storybook/addon-links": "^4.0.0-rc.0",
    "@storybook/addons": "^4.0.0-rc.0",
    "babel-loader": "^8.0.4"
  }

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 54 (43 by maintainers)

Commits related to this issue

Most upvoted comments

OK, I’ll work on this. I can make a version that has some sort of migration path for Babel 6 users.

It is 2020 and babel-preset-vue is still in the code and docs. This makes Storybook unusable out-of-the-box when using vue-cli and the storybook-vue guide. (1. Install vue-cli 2. Create a new vue project 3. Try to add storybook according to the guide. It forces you to install babel-preset-vue which is completely unnecessary.)

What do we need to do here?

As @pksunkara mentioned, we could just get rid of it altogether? Nobody creating a new project today would use Babel 6.

/Edit: If anyone wants a quick workaround, I created a minimal Storybook-Vue-TS repository which uses a patch file to get rid of this requirement.

You need to add your custom loaders (looks like you’re using stylus) to the storybook webpack config too @crusenov.

The current issue really isn’t related to this though, https://github.com/storybookjs/vue-cli-plugin-storybook/issues/23 looks to be more suited, or open a new issue if you believe there’s a bug. Thanks!

@backbone87 @pksunkara I’m fine as long as we have great documentation and support for the latest and greatest. Older versions can be in the documentation or even documented in issues. really feels like storybook for Vue could use a little love ❤️

As far as I can see the fix here is to just remove the automatic inclusion of that preset and make it clear in the documentation that users should specify a preset themselves? (Which in most cases will have already been taken care of.)

Can someone reiterate why that preset is there in the first place? It seems counter-intuitive to forcefully add babel presets to existing babel projects.

Will do @shilman 👍

I ran into this problem while migrating from webpack 3/stroybook 3 to webpack 4/storybook 4. We removed the babel preset as we don’t use it anymore in our vue build. I think at least this should be added as a peer dependency until it is clear how to proceed. As the preset is requirered at runtime it has to be some kind of dependency.

"dependencies": {
    "vue": "^2.5.17",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "@babel/core": "^7.1.5",
    "@storybook/vue": "^4.0.0-rc.6",
    "@vue/cli-plugin-babel": "^3.1.1",
    "@vue/cli-plugin-eslint": "^3.1.1",
    "@vue/cli-service": "^3.1.1",
    "babel-core": "^6.26.3",
    "babel-eslint": "^10.0.1",
    "babel-loader": "^8.0.4",
    "eslint": "^5.8.0",
    "eslint-plugin-vue": "^5.0.0-0",
    "vue-loader": "^15.4.2",
    "vue-template-compiler": "^2.5.17"
  },

I use vue-cli@3 , I encountered the same problem on window 10

In the interests of not blocking the SB4 release: https://github.com/storybooks/storybook/pull/4535

There may be better solutions, but AFAICT this works and doesn’t introduce problems. We can do a better fix in a 4.0.1 perhaps?

I’m confused here. AFAICT this is a blocker for the 4.0 release—any chance we can get some clarity on this in the next day or so?

Here’s a small update. While working on #10813 I tried to remove babel-preset-vue from storybook’s vue preset. Existing projects relying on it can be pretty easily migrated by adding it back in manually, but I ran into a bunch of problems with the E2E tests (sb init). I may be mistaken but this is how I understand it now.

As far as I can tell, the SFC_VUE e2e test does this:

  1. Create an empty package and install ‘vue-loader’
  2. Run sb init, which recognizes the project as a SFC_VUE project, based on the ‘vue-loader’ dep
  3. sb init generates some components and stories based on fixtures. One of those example stories uses JSX.
  4. storybook build works only if you have babel-preset-vue (that adds support for JSX). It fails if that preset is missing from the babel config.

My questions:

  • Is this a valid scenario? Does anyone use vue in this way?
  • What’s the reason for the distinction between VUE and SFC_VUE anyway? Is that maybe obsolete?
  • The main reason the tests fail after the change is missing JSX support which came from babel-preset-vue (I think?). Without that preset, no JSX. Maybe we could remove the use of JSX in the generated story? Users of JSX in Vue should be using another babel plugin anyway according to the vue docs.
  • OR since this problem really is just in the story code, shouldn’t JSX be handled by the babel config provided by storybook? Why does this expect to have JSX support through babel-preset-vue?

I think what we need to do is

  1. Make that test work without babel-preset-vue (at the moment, there’s a weird cross-dependency from the story js code to that preset)
  2. Review the officially endorsed ways of using Vue and adjust the test cases to that
  3. Finally, remove all mentions of babel-preset-vue from the code
  4. Wait for Vue 3 to come out soon and probably have a lot of new issues 😉

Some more code references:

@graup any chance you can take a crack at this? We’re working on storybook 6.0 right now, so there’s never been a better time to make a breaking change

We should definitely get rid of babel-preset-vue, as far as I can tell that is not even compatible with Babel 7 (it’s from the time before babel switched from the babel-preset-name naming to @babel/name). I tried to use JSX in Vue with it and it creates all sorts of errors.

For now, is there a workaround to tell @storyboard/vue to NOT require babel-preset-vue? I want to use @vue/app or @vue/babel-preset-app instead, as specified in my babel config.

Nothing changed, so probably this bug is still there. Nothing to close here!