[英]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 ng版本
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}:作为解决方法,我更新了从 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.
:( 这适用于版本 6.0.12。
Updates: With newer version of the storybook(>6.2.*), Explicitly declare in typings.d.ts inside the.storybook directory.更新:使用较新版本的故事书(>6.2.*),在 .storybook 目录中的 typings.d.ts 中明确声明。 (mentioned by @Mr.7)
(@Mr.7提到)
declare module '@storybook/angular'
In my case, I tried Subhakant's workaround but that didn't work for me.就我而言,我尝试了 Subhakant 的解决方法,但这对我不起作用。 After some research I found this.
经过一番研究,我发现了这一点。
The explicit declaration in typings.d.ts inside .storybook directory made it work .storybook目录中typings.d.ts中的显式声明使其工作
declare module '@storybook/angular'
For me none of this worked.对我来说,这些都不起作用。 I used
npx sb init
to add storybook to an existing Angular 6 project.我使用 npx
npx sb init
将故事书添加到现有的 Angular 6 项目中。 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.遗憾的是,它没有正确设置故事书,我收到了与 OP 相同的错误,但这里的解决方案都不适合我。 Finally I realized, that my typescript version was outdated (3.8.4) but the setup was for TS 3.9.
最后我意识到,我的 typescript 版本已经过时 (3.8.4),但设置是针对 TS 3.9 的。 I updated typescript to 3.10.4 everything works now.
我将 typescript 更新为 3.10.4 现在一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.