简体   繁体   中英

Angular 8 with Storybook 6

Getting the below error while installing and starting a storybook.

ERROR in /Users/username/angular-storybook/src/stories/Button.stories.ts
ERROR in /Users/username/angular-storybook/src/stories/Button.stories.ts(2,29):
TS2307: Cannot find module '@storybook/angular/types-6-0'.

ng version

Angular CLI: 8.3.29
Node: 12.16.2
OS: darwin x64
Angular: 8.2.14

Dev dependency

    "@compodoc/compodoc": "^1.1.11",
    "@storybook/addon-actions": "^6.0.12",
    "@storybook/addon-essentials": "^6.0.12",
    "@storybook/addon-links": "^6.0.12",
    "@storybook/angular": "^6.0.12"

As a workaround, I have updated the imports from Button, Header, Page{.stories}:

From --->
import { Story, Meta } from '@storybook/angular/types-6-0';

To  ---->
import { Story, Meta } from '@storybook/angular';

This works fine. But not sure why the boilerplate code has the issue. :( This works fine with version 6.0.12.

Updates: With newer version of the storybook(>6.2.*), Explicitly declare in typings.d.ts inside the.storybook directory. (mentioned by @Mr.7)

declare module '@storybook/angular'

In my case, I tried Subhakant's workaround but that didn't work for me. After some research I found this.

The explicit declaration in typings.d.ts inside .storybook directory made it work

declare module '@storybook/angular'

For me none of this worked. I used npx sb init to add storybook to an existing Angular 6 project. Sadly it did not set up storybook correctly and I received the same error as OP, yet none of the solutions here worked for me. Finally I realized, that my typescript version was outdated (3.8.4) but the setup was for TS 3.9. I updated typescript to 3.10.4 everything works now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM