How to install storybook with vue + type script
See original GitHub issueHello, I’m trying to install storybook with vue+typescript
I have used this article and comments as a manual.
After all of this I have an error in dev tools console: [Vue warn]: Cannot find element: #root
And page automatically redirects to http://localhost:6006/?selectedKind=Button&selectedStory=with text

webpack.config.js :
const merge = require('webpack-merge')
const genStorybookDefaultConfig = require('@storybook/vue/dist/server/framework-preset-vue.js')
.webpack
const vueConfig = require('@vue/cli-service/webpack.config.js')
module.exports = (storybookBaseConfig, configType) => {
const storybookConfig = genStorybookDefaultConfig(
storybookBaseConfig,
configType
)
return {
...vueConfig, // use vue's webpack configuration by default
entry: storybookConfig.entry, // overwite entry
output: storybookConfig.output, // overwrite output
// remove duplicated plugins
plugins: merge({
customizeArray: merge.unique(
'plugins',
[
'HotModuleReplacementPlugin',
'CaseSensitivePathsPlugin',
'WatchMissingNodeModulesPlugin',
'VueLoaderPlugin'
],
plugin => plugin.constructor && plugin.constructor.name
)
})(vueConfig, storybookConfig).plugins,
resolve: {
...vueConfig.resolve,
alias: {
...vueConfig.resolve.alias,
vue$: storybookConfig.resolve.alias.vue$
}
}
}
}
config.js:
import { configure } from '@storybook/vue'
// automatically import all files ending in *.stories.ts
const req = require.context('../src/stories', true, /.stories.ts$/)
function loadStories() {
req.keys().forEach(filename => req(filename))
}
configure(loadStories, module)
index.stories.ts :
/* eslint-disable react/react-in-jsx-scope, react/no-this-in-sfc */
import { storiesOf } from '@storybook/vue'
import { action } from '@storybook/addon-actions'
// import { linkTo } from '@storybook/addon-links'
import MyButton from './MyButton.vue'
storiesOf('Button', module)
.add('with text', () => ({
components: { MyButton },
template: <my-button @click="action">Hello Button</my-button>
methods: { action: action('clicked') }
}))
.add('with some emoji', () => ({
components: { MyButton },
template: '<my-button @click="action">😀 😎 👍 💯</my-button>',
methods: { action: action('clicked') }
}))
/* eslint-enable react/react-in-jsx-scope */
Repo Any thoughts ?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
Configuring Storybook for Vue with TypeScript - Damir's Corner
Configuring Storybook for Vue with TypeScript ... Storybook is a great tool for component development. But although it supports many frameworks, ...
Read more >Getting started with Vue (2.x), Storybook and Typescript
In this article, we will take a look at getting started with Storybook and VueJS (2.x) and in particular, using Typescript, class-style ...
Read more >Building #Vue components in #TypeScript using #Storybook
Welcome to The SingleStore #Developer Live Stream. In this episode, we use # storybook as a harness to quickly develop and flex a...
Read more >How to install Storybook to VueJS 2 TypeScript project?
npx sb init. according to the latest documentation - https://storybook.js.org/docs/vue/get-started/install.
Read more >Storybook for Vue 3 - JS.ORG
Storybook is an open source tool for building UI components. It speeds up UI development, generates documentation, and automates testing. This ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If someone still has problems with it this should help 😃
Thanks for trying the config @justinhodev It depends what kind of components you are compiling - if you use render functions it will work without this alias.
vs
See: https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
Probably you are using the template option, that is why esm build is required.
Hope it explains why it didn’t work without it 😃
Cheers, Mateusz