storybook icon indicating copy to clipboard operation
storybook copied to clipboard

Nuxt + typescript + Storybook = Error must install `typescript`

Open lowbits opened this issue 4 years ago • 20 comments

Version

@nuxtjs/storybook: ^3.3.1 nuxt: 2.14.6 fork-ts-checker-webpack-plugin: ^6.1.0

What is actually happening?

After installing storybook by the documentation, i can't either run yarn nuxt or yarn nuxt-storybook. Even if i turn off checked in nuxt.config

storybook { typescript: { check: false } } Booth produce following error:

Error: When you use this plugin you must install typescript. at ForkTsCheckerWebpackPlugin.validateTypeScript (/Users/_/git/_/node_modules/fork-ts-checker-webpack-plugin/src/index.ts:250:13) at new ForkTsCheckerWebpackPlugin (/Users/_/git/_/node_modules/fork-ts-checker-webpack-plugin/src/index.ts:197:14) at WebpackBundler.<anonymous> (/Users/_/git/_/node_modules/@nuxt/typescript-build/src/index.ts:77:28) at WebpackBundler.<anonymous> (/Users/_/git/_/node_modules/@nuxt/utils/dist/utils.js:1888:29) at WebpackBundler.<anonymous> (/Users/_/git/_/node_modules/@nuxt/utils/dist/utils.js:1888:29) at WebpackBundler.<anonymous> (/Users/_/git/_/node_modules/@nuxt/utils/dist/utils.js:1888:29) at WebpackClientConfig.extendConfig (/Users/_/git/_/node_modules/@nuxt/webpack/dist/webpack.js:4879:37) at WebpackClientConfig.config (/Users/_/git/_/node_modules/@nuxt/webpack/dist/webpack.js:4914:45) at WebpackClientConfig.config (/Users/_/git/_/node_modules/@nuxt/webpack/dist/webpack.js:5078:26) at WebpackBundler.getWebpackConfig (/Users/_/git/_/node_modules/@nuxt/webpack/dist/webpack.js:5386:19) at /Users/_/git/_/node_modules/@nuxtjs/storybook/dist/index.js:106:55 at Generator.next (<anonymous>) at fulfilled (/Users/_/git/_/node_modules/@nuxtjs/storybook/dist/index.js:5:58

lowbits avatar Jan 26 '21 08:01 lowbits

Hey, thank you for the report :slightly_smiling_face: Could you provide a reproduction sample on codesandbox?

farnabaz avatar Jan 26 '21 08:01 farnabaz

I have the same problem

TinaDrog avatar Jan 26 '21 11:01 TinaDrog

Trying to repoduce this issue. Dont know if it has something todo with yarn workspaces and a plugin which uses typescript and composition-api. If i can reproduce the issue, i will provide it.

lowbits avatar Jan 26 '21 11:01 lowbits

Fixed my problem by adding noHoist in my root package.json. Then delete all node_modules and yarn.lock.

"workspaces": {
    "packages": [
      "packages/*"
    ],
    "nohoist": [
      "**/fork-ts-checker-webpack-plugin",
      "**/fork-ts-checker-webpack-plugin/**"
    ]
  },

lowbits avatar Jan 29 '21 08:01 lowbits

@lowbits What is your node version?

farnabaz avatar Jan 29 '21 09:01 farnabaz

@lowbits What is your node version?

v15.7.0

lowbits avatar Jan 29 '21 09:01 lowbits

But i have now this problem

ERROR in ./.nuxt-storybook/components/index.js
Module build failed (from /Users/_/git/_/node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/_/git/_/packages/storefront-example/.nuxt-storybook/components/index.js: Unexpected token, expected "," (15:31)

  13 | export { default as SideNavigation } from '../../components/navigation/SideNavigation.vue'
  14 | export { default as SideNavigationList } from '../../components/navigation/SideNavigationList.vue'
> 15 | export { default as ProductCard.stories } from '../../components/product/ProductCard.stories.ts'

with a marker at the dot from ProductCard.stories

lowbits avatar Jan 29 '21 09:01 lowbits

Unfortunately I couldn't reproduce the issue to find the cause

farnabaz avatar Jan 29 '21 09:01 farnabaz

Okay, clone this repo, create an Logo.stories.ts in ``packages/nuxt-composition-api-storybook/components```

with

import { storiesOf } from '@storybook/vue'
import Logo from '~/components/Logo.vue'

storiesOf('Logo', module).add('default', () => ({
  components: { Logo },
  template: `
      <Logo :product="mockedProduct"/>`,
}))

run yarn nuxt storybookin packages/nuxt-composition-api-storybook

lowbits avatar Jan 29 '21 10:01 lowbits

This Error only occurs when ProductCard.stories.ts start with uppercase letter.

ERROR in ./.nuxt-storybook/components/index.js
Module build failed (from /Users/_/git/_/node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/_/git/_/packages/storefront-example/.nuxt-storybook/components/index.js: Unexpected token, expected "," (15:31)

  13 | export { default as SideNavigation } from '../../components/navigation/SideNavigation.vue'
  14 | export { default as SideNavigationList } from '../../components/navigation/SideNavigationList.vue'
> 15 | export { default as ProductCard.stories } from '../../components/product/ProductCard.stories.ts'

lowbits avatar Jan 29 '21 12:01 lowbits

I see, ignoring typescript stories in Nuxt components will do the trick. Update nuxt.config.js:

export default {
  componets: {
     path: "~/components",
     ignore: '**/*.stories.ts'
  }
}

farnabaz avatar Jan 29 '21 15:01 farnabaz

@farnabaz I speficied your snippet like this to comply with the type declarations, not sure if it still has the same meaning:

components: {
    dirs: [
      {
        path: "~/components",
        ignore: ["**/*.stories.ts"]
      }
    ]
  }

Did not work for me. Before that I've tried the linked bugfix by updating to v1.2.6 and manually checking if the changes are present in the file system. Executing nuxt generate still caused me to get complaints about imports and subsequently missing dev dependencies, etc. related to the storybook file (which should be ignored). WIth and without the bugfix (or the nuxt config change), the only way to get storybook files ignored was for me to stop using nuxt components or not using typescript in stories at all.

gekkedev avatar Feb 10 '21 11:02 gekkedev

Yeah, dont use nuxt-components auto import, it is better for performance reasons anyway.

lowbits avatar Feb 10 '21 11:02 lowbits

If you efficiently balance your use of lazy-loading there should be nothing wrong with nuxt-components. I'm still looking for a solution though and not a workaround. There already is a bugfix in place at nuxt/components#135 to prevent accidentally importing stories, but it doesn't seem to work for me.

gekkedev avatar Feb 10 '21 12:02 gekkedev

@gekkedev The good news is, Nuxt 2.15.0 is out. Just update your Nuxt and issue will resolve :)

farnabaz avatar Feb 16 '21 12:02 farnabaz

@gekkedev The good news is, Nuxt 2.15.0 is out. Just update your Nuxt and issue will resolve :)

I have Nuxt 2.15.1 and this issue persist

MrJmpl3 avatar Feb 20 '21 04:02 MrJmpl3

Same for me, the issue still persists after updating Nuxt. It used to occur when doing a storybook generate, but with Nuxt 2.15 it also affects nuxt dev. That's currently keeping me from updating.

gekkedev avatar Feb 23 '21 19:02 gekkedev

I encountered same error, and this command worked for me.

yarn add -D typescript fork-ts-checker-webpack-plugin

fujiten avatar May 13 '21 14:05 fujiten

@farnabaz some problem "@nuxtjs/storybook": "^4.0.2", yarn nuxt storybook build CleanShot_2021-05-15_at_08 57 39

productdevbook avatar May 15 '21 07:05 productdevbook

What worked for me was adding yarn add -D @storybook/preset-typescript then adding in nuxt.config.ts

storybook: {
    addons: [
      '@storybook/preset-typescript',
      ..
      ]
 }

seuros avatar Aug 18 '21 20:08 seuros

v4 of this module is no longer actively supported. Please try the newest version and open an new issue if the problem persists. Thank you for your understanding.

tobiasdiez avatar May 01 '24 07:05 tobiasdiez