Skip to content
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

VueJS TypeScript Property Decorators Error #10327

Closed
slavarazum opened this issue Apr 6, 2020 · 8 comments
Closed

VueJS TypeScript Property Decorators Error #10327

slavarazum opened this issue Apr 6, 2020 · 8 comments

Comments

@slavarazum
Copy link

Describe the bug
Looks like @storybook/preset-typescript can't interpret decorators from vue-property-decorators, like: @Component

Error screenshot:
screenshot

Error text:

Support for the experimental syntax 'decorators-legacy' isn't currently enabled

Code snippets

main.js

const path = require('path');

// your app's webpack.config.js
const custom = require('../webpack.config.js');

module.exports = {
  stories: ['../stories/**/*.stories.[tj]s'],
  addons: [
    '@storybook/preset-typescript',
    '@storybook/addon-actions',
    '@storybook/addon-links',
  ],

  webpackFinal: (config) => {
    return {
      ...config,
      resolve: {
        ...config.resolve,
        alias: custom.resolve.alias,
      }
    };
  }
};

1-TestComponent.stories.ts

import { action } from '@storybook/addon-actions';

import TestComponent from './TestComponent';

export default {
  title: 'TestComponent',
  component: TestComponent,
};

export const Simple = () => ({
  components: { TestComponent },
  template: '<TestComponent>Some text</TestComponent>',
  methods: { action: action('clicked') },
});

TestComponent.vue

<template>
  <div>
    <slot />
  </div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';

@Component({ name: 'TestComponent' })
export default class TestComponent extends Vue {}
</script>

System:

Environment Info:

  System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  Binaries:
    Node: 13.10.1 - /usr/local/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.7 - /usr/local/bin/npm
  Browsers:
    Chrome: 80.0.3987.149
    Firefox: 74.0.1
    Safari: 13.1
  npmPackages:
    @storybook/addon-actions: ^5.3.18 => 5.3.18 
    @storybook/addon-links: ^5.3.18 => 5.3.18 
    @storybook/addons: ^5.3.18 => 5.3.18 
    @storybook/preset-typescript: ^3.0.0 => 3.0.0 
    @storybook/vue: ^5.3.18 => 5.3.18 

Additional context
Also have tried to pass tsconfig.json path:

main.js

addons: [
    {
      name: '@storybook/preset-typescript',
      options: {
        tsLoaderOptions: {
          configFile: path.resolve(__dirname, '../tsconfig.json'),
        },
      },
    },
  ],
@metanas
Copy link

metanas commented Apr 6, 2020

You should add ts-loader to your webpack configuration in main.js of your storybook

module.exports = {
  stories: ['../stories/**/*.stories.[tj]s'],
  addons: [
    '@storybook/preset-typescript',
    '@storybook/addon-actions',
    '@storybook/addon-links',
  ],

  webpackFinal: (config) => {
    config.module.rules.push({
      test: /\.ts$/,
      exclude: /node_modules/,
      use: [{
        loader: 'ts-loader',
        options: {
          appendTsSuffixTo: [/\.vue$/],
          transpileOnly: true
        },
      }],
    });
    return {
      ...config,
      resolve: {
        ...config.resolve,
        alias: custom.resolve.alias,
      }
    };
  }
};

@shilman
Copy link
Member

shilman commented Apr 7, 2020

Thanks for reporting @slavarazum and for the workaround @metanas. We have an open PR for that here, but are still figuring out the best path forward: storybookjs/presets#122

@slavarazum
Copy link
Author

@metanas Thanks for help! I thought ts-loader included under the hood.

Also, for non vue-clie presets we should add runtime compiler:

config.resolve.alias['vue$'] = 'vue/dist/vue.esm.js';

@shilman Thanks for the link, just have subscribed.

@stale
Copy link

stale bot commented Apr 29, 2020

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!

@stale stale bot added the inactive label Apr 29, 2020
@shilman
Copy link
Member

shilman commented May 21, 2020

We've just released zero-config typescript support in 6.0-beta. Please upgrade and test it!

Thanks for your help and support getting this stable for release!

@stale stale bot removed the inactive label May 21, 2020
@stale
Copy link

stale bot commented Jun 12, 2020

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!

@stale stale bot added the inactive label Jun 12, 2020
@stale
Copy link

stale bot commented Jul 12, 2020

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

@stale stale bot closed this as completed Jul 12, 2020
@caryuval
Copy link

Before messing with the TS configs or upgrading Storybook, I suggest making sure that you didn't forget to add
lang="ts" in your script tag, like so: <script lang="ts">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants