storybook [Bug]: docs.source.format 不接受 "typescript" 作为解析器

olmpazwi  于 3个月前  发布在  TypeScript
关注(0)|答案(1)|浏览(38)

描述错误

设置 docs.source.format: "typescript" 时,会抛出以下错误:

Couldn't resolve parser "typescript". Parsers must be explicitly added to the standalone bundle.

根据讨论 here ,我的理解是这是由于 prettierTypescript 插件没有被加载。
作为解决方法,我们正在使用 transformSource (即将更新为 transform)手动拉入解析器:

import prettier from "prettier/standalone";
import prettierTypescript from "prettier/parser-typescript";

export const parameters = {
  docs: {
    source: {
      transformSource: (src: string) => 
        prettier.format(src, {
          parser: "typescript",
          plugins: [prettierTypescript]
        }),
      },
    },
};

重现问题

  • 无响应*

系统信息

  • 无响应*

其他上下文信息

  • 无响应*
ldfqzlk8

ldfqzlk81#

即使使用这个解决方法,我仍然得到:

Couldn't resolve parser "typescript". Plugins must be explicitly added to the standalone bundle.

有什么想法吗?

相关问题