You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ionic Angular中Storybook启动报错:polyfills.ts未纳入TS编译

在Ionic Angular项目中启动Storybook时遇到polyfills.ts编译错误

启动Storybook时出现如下编译错误:

ERROR in ./src/polyfills.ts 
Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: C:\Users\foo\workspaces\tmp\photo-gallery\src\polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at C:\Users\foo\workspaces\tmp\photo-gallery\node_modules\@ngtools\webpack\src\ivy\loader.js:75:26

报错复现步骤

  • 全局安装Ionic工具链:npm install -g @ionic/cli native-run cordova-res
  • 创建Ionic Angular项目:ionic start photo-gallery tabs --type=angular --capacitor
  • 初始化Storybook:npx storybook@latest init

已验证信息

  • 测试独立组件和NgModules组件均触发错误
  • Windows和Mac系统下都能复现该问题
  • 纯Angular项目无此问题,确认错误与ionic/angular相关

修复方案

问题根源是Storybook的TypeScript配置未包含polyfills.ts文件,按以下步骤修改:

  1. 打开项目根目录下的.storybook/tsconfig.json文件
  2. 在include数组中添加../src/polyfills.ts,修改后的配置示例:
{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "outDir": "../out-tsc/storybook",
    "types": ["node"]
  },
  "include": [
    "../src/**/*.stories.ts",
    "../src/**/*.stories.js",
    "../src/**/*.stories.tsx",
    "../src/**/*.stories.jsx",
    "../src/polyfills.ts"
  ]
}
  1. 保存配置后,重新启动Storybook:npm run storybook

内容的提问来源于stack exchange,提问作者Xero

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 07:31:05