import CJS_COMPAT_NODE_URL from 'node:url';
import CJS_COMPAT_NODE_PATH from 'node:path';
import CJS_COMPAT_NODE_MODULE from "node:module";

const __filename = CJS_COMPAT_NODE_URL.fileURLToPath(import.meta.url);
const __dirname = CJS_COMPAT_NODE_PATH.dirname(__filename);
const require = CJS_COMPAT_NODE_MODULE.createRequire(import.meta.url);
// ------------------------------------------------------------
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
// ------------------------------------------------------------
import {
  a as G
} from "./chunk-5G5PMXGR.js";
import {
  a as D
} from "./chunk-E3SD6WWV.js";
import {
  a as r,
  f as d
} from "./chunk-HRN2KQZP.js";

// src/server-errors.ts
var u = d(D(), 1), n = d(G(), 1);

// src/storybook-error.ts
function g({
  code: t,
  category: a
}) {
  let o = String(t).padStart(4, "0");
  return `SB_${a}_${o}`;
}
r(g, "parseErrorCode");
var s = class t extends Error {
  constructor(o) {
    super(t.getFullMessage(o));
    /**
     * Data associated with the error. Used to provide additional information in the error message or
     * to be passed to telemetry.
     */
    this.data = {};
    /** Flag used to easily determine if the error originates from Storybook. */
    this.fromStorybook = !0;
    this.category = o.category, this.documentation = o.documentation ?? !1, this.code = o.code;
  }
  static {
    r(this, "StorybookError");
  }
  get fullErrorCode() {
    return g({ code: this.code, category: this.category });
  }
  /** Overrides the default `Error.name` property in the format: SB_<CATEGORY>_<CODE>. */
  get name() {
    let o = this.constructor.name;
    return `${this.fullErrorCode} (${o})`;
  }
  /** Generates the error message along with additional documentation link (if applicable). */
  static getFullMessage({
    documentation: o,
    code: c,
    category: l,
    message: p
  }) {
    let i;
    return o === !0 ? i = `https://storybook.js.org/error/${g({ code: c, category: l })}` : typeof o == "string" ? i = o : Array.isArray(o) && (i = `
${o.map((U) => `	- ${U}`).join(`
`)}`), `${p}${i != null ? `

More info: ${i}
` : ""}`;
  }
};

// src/server-errors.ts
var Y = /* @__PURE__ */ ((e) => (e.CLI = "CLI", e.CLI_INIT = "CLI_INIT", e.CLI_AUTOMIGRATE = "CLI_AUTOMIGRATE", e.CLI_UPGRADE = "CLI_UPGRADE", e.CLI_ADD = "CLI_ADD", e.CODEMOD = "CODEMOD", e.CORE_SERVER = "CORE-SERVER", e.CSF_PLUGIN = "CSF-PLUGIN", e.CSF_TOOLS = "CSF-TOOLS", e.CORE_COMMON = "CORE-COMMON", e.NODE_LOGGER = "NODE-LOGGER", e.TELEMETRY = "TELEMETRY", e.BUILDER_MANAGER = "BUILDER-MANAGER", e.BUILDER_VITE = "BUILDER-VITE", e.BUILDER_WEBPACK5 = "BUILDER-WEBPACK5", e.SOURCE_LOADER = "SOURCE-LOADER", e.POSTINSTALL = "POSTINSTALL", e.DOCS_TOOLS = "DOCS-TOOLS", e.CORE_WEBPACK = "CORE-WEBPACK", e.FRAMEWORK_ANGULAR = "FRAMEWORK_ANGULAR", e.FRAMEWORK_EMBER = "FRAMEWORK_EMBER", e.FRAMEWORK_HTML_VITE = "FRAMEWORK_HTML-VITE", e.FRAMEWORK_HTML_WEBPACK5 = "FRAMEWORK_HTML-WEBPACK5", e.FRAMEWORK_NEXTJS = "FRAMEWORK_NEXTJS", e.FRAMEWORK_PREACT_VITE = "FRAMEWORK_PREACT-VITE", e.FRAMEWORK_PREACT_WEBPACK5 = "FRAMEWORK_PREACT-WEBPACK5", e.FRAMEWORK_REACT_VITE = "FRAMEWORK_REACT-VITE", e.FRAMEWORK_REACT_WEBPACK5 = "FRAMEWORK_REACT-WEBPACK5", e.FRAMEWORK_SERVER_WEBPACK5 = "FRAMEWORK_SERVER-WEBPACK5", e.FRAMEWORK_SVELTE_VITE = "FRAMEWORK_SVELTE-VITE", e.FRAMEWORK_SVELTEKIT = "FRAMEWORK_SVELTEKIT", e.FRAMEWORK_VUE_VITE = "FRAMEWORK_VUE-VITE", e.FRAMEWORK_VUE_WEBPACK5 = "FRAMEWORK_VUE-WEBPACK5", e.FRAMEWORK_VUE3_VITE = "FRAMEWORK_VUE3-VITE", e.FRAMEWORK_VUE3_WEBPACK5 = "FRAMEWORK_VUE3-WEBPACK5", e.FRAMEWORK_WEB_COMPONENTS_VITE = "FRAMEWORK_WEB-COMPONENTS-VITE", e.FRAMEWORK_WEB_COMPONENTS_WEBPACK5 = "FRAMEWORK_WEB-COMPONENTS-WEBPACK5", e))(Y || {}), y = class extends s {
  static {
    r(this, "NxProjectDetectedError");
  }
  constructor() {
    super({
      category: "CLI_INIT",
      code: 1,
      documentation: "https://nx.dev/nx-api/storybook#generating-storybook-configuration",
      message: n.dedent`
        We have detected Nx in your project. Nx has its own Storybook initializer, so please use it instead.
        Run "nx g @nx/storybook:configuration <your-project-name>" to add Storybook to a given Nx app or lib.`
    });
  }
}, m = class extends s {
  static {
    r(this, "MissingFrameworkFieldError");
  }
  constructor() {
    super({
      category: "CORE-COMMON",
      code: 1,
      documentation: "https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#new-framework-api",
      message: n.dedent`
        Could not find a 'framework' field in Storybook config.
        
        Please run 'npx storybook automigrate' to automatically fix your config.`
    });
  }
}, E = class extends s {
  constructor(o) {
    super({
      category: "CORE-COMMON",
      code: 2,
      documentation: "https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#new-framework-api",
      message: n.dedent`
        Invalid value of '${o.frameworkName}' in the 'framework' field of Storybook config.
        
        Please run 'npx storybook automigrate' to automatically fix your config.
      `
    });
    this.data = o;
  }
  static {
    r(this, "InvalidFrameworkNameError");
  }
}, b = class extends s {
  constructor(o) {
    super({
      category: "CORE-COMMON",
      code: 3,
      documentation: "",
      message: n.dedent`
        Could not evaluate the '${o.frameworkName}' package from the 'framework' field of Storybook config.
        
        Are you sure it's a valid package and is installed?`
    });
    this.data = o;
  }
  static {
    r(this, "CouldNotEvaluateFrameworkError");
  }
}, R = class extends s {
  static {
    r(this, "ConflictingStaticDirConfigError");
  }
  constructor() {
    super({
      category: "CORE-SERVER",
      code: 1,
      documentation: "https://storybook.js.org/docs/configure/integration/images-and-assets#serving-static-files-via-storybook-configuration",
      message: n.dedent`
        Storybook encountered a conflict when trying to serve statics. You have configured both:
        * Storybook's option in the config file: 'staticDirs'
        * Storybook's (deprecated) CLI flag: '--staticDir' or '-s'
        
        Please remove the CLI flag from your storybook script and use only the 'staticDirs' option instead.`
    });
  }
}, f = class extends s {
  static {
    r(this, "InvalidStoriesEntryError");
  }
  constructor() {
    super({
      category: "CORE-COMMON",
      code: 4,
      documentation: "https://storybook.js.org/docs/faq#can-i-have-a-storybook-with-no-local-stories",
      message: n.dedent`
        Storybook could not index your stories.
        Your main configuration somehow does not contain a 'stories' field, or it resolved to an empty array.
        
        Please check your main configuration file and make sure it exports a 'stories' field that is not an empty array.`
    });
  }
}, h = class extends s {
  static {
    r(this, "WebpackMissingStatsError");
  }
  constructor() {
    super({
      category: "BUILDER-WEBPACK5",
      code: 1,
      documentation: [
        "https://webpack.js.org/configuration/stats/",
        "https://storybook.js.org/docs/builders/webpack#configure"
      ],
      message: n.dedent`
        No Webpack stats found. Did you turn off stats reporting in your Webpack config?
        Storybook needs Webpack stats (including errors) in order to build correctly.`
    });
  }
}, k = class extends s {
  constructor(o) {
    super({
      category: "BUILDER-WEBPACK5",
      code: 2,
      message: o.error.message.trim()
    });
    this.data = o;
  }
  static {
    r(this, "WebpackInvocationError");
  }
};
function O(t = "") {
  return t.replace(/\u001B\[[0-9;]*m/g, "");
}
r(O, "removeAnsiEscapeCodes");
var A = class extends s {
  constructor(o) {
    o.errors = o.errors.map((c) => ({
      ...c,
      message: O(c.message),
      stack: O(c.stack),
      name: c.name
    }));
    super({
      category: "BUILDER-WEBPACK5",
      code: 3,
      // This error message is a followup of errors logged by Webpack to the user
      message: n.dedent`
        There were problems when compiling your code with Webpack.
        Run Storybook with --debug-webpack for more information.
      `
    });
    this.data = o;
  }
  static {
    r(this, "WebpackCompilationError");
  }
}, _ = class extends s {
  constructor(o) {
    super({
      category: "CLI_INIT",
      code: 2,
      documentation: "https://storybook.js.org/docs/faq#error-no-angularjson-file-found",
      message: n.dedent`
        An angular.json file was not found in the current working directory: ${o.path}
        Storybook needs it to work properly, so please rerun the command at the root of your project, where the angular.json file is located.`
    });
    this.data = o;
  }
  static {
    r(this, "MissingAngularJsonError");
  }
}, x = class extends s {
  static {
    r(this, "AngularLegacyBuildOptionsError");
  }
  constructor() {
    super({
      category: "FRAMEWORK_ANGULAR",
      code: 1,
      documentation: [
        "https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#angular-drop-support-for-calling-storybook-directly",
        "https://github.com/storybookjs/storybook/tree/next/code/frameworks/angular#how-do-i-migrate-to-an-angular-storybook-builder"
      ],
      message: n.dedent`
        Your Storybook startup script uses a solution that is not supported anymore.
        You must use Angular builder to have an explicit configuration on the project used in angular.json.
        
        Please run 'npx storybook automigrate' to automatically fix your config.`
    });
  }
}, I = class extends s {
  constructor(o) {
    super({
      category: "CORE-SERVER",
      code: 2,
      documentation: "",
      message: n.dedent`
        Storybook failed to load the following preset: ${o.presetName}.
        
        Please check whether your setup is correct, the Storybook dependencies (and their peer dependencies) are installed correctly and there are no package version clashes.
        
        If you believe this is a bug, please open an issue on Github.
        
        ${o.error.stack || o.error.message}`
    });
    this.data = o;
  }
  static {
    r(this, "CriticalPresetLoadError");
  }
}, S = class extends s {
  static {
    r(this, "MissingBuilderError");
  }
  constructor() {
    super({
      category: "CORE-SERVER",
      code: 3,
      documentation: "https://github.com/storybookjs/storybook/issues/24071",
      message: n.dedent`
        Storybook could not find a builder configuration for your project. 
        Builders normally come from a framework package e.g. '@storybook/react-vite', or from builder packages e.g. '@storybook/builder-vite'.
        
        - Does your main config file contain a 'framework' field configured correctly?
        - Is the Storybook framework package installed correctly?
        - If you don't use a framework, does your main config contain a 'core.builder' configured correctly?
        - Are you in a monorepo and perhaps the framework package is hoisted incorrectly?
        
        If you believe this is a bug, please describe your issue in detail on Github.`
    });
  }
}, C = class extends s {
  constructor(o) {
    super({
      category: "FRAMEWORK_NEXTJS",
      code: 1,
      documentation: "https://github.com/storybookjs/storybook/blob/next/code/frameworks/nextjs/README.md#nextjs-font-optimization",
      message: n.dedent`
        Failed to fetch \`${o.fontFamily}\` from Google Fonts with URL: \`${o.url}\``
    });
    this.data = o;
  }
  static {
    r(this, "GoogleFontsDownloadError");
  }
}, T = class extends s {
  constructor(o) {
    super({
      category: "FRAMEWORK_NEXTJS",
      code: 2,
      documentation: "https://github.com/storybookjs/storybook/blob/next/code/frameworks/nextjs/README.md#nextjs-font-optimization",
      message: n.dedent`
        An error occurred when trying to load Google Fonts with URL \`${o.url}\`.
        
        ${o.error instanceof Error ? o.error.message : ""}`
    });
    this.data = o;
  }
  static {
    r(this, "GoogleFontsLoadingError");
  }
}, w = class extends s {
  static {
    r(this, "SvelteViteWithSvelteKitError");
  }
  constructor() {
    super({
      category: "FRAMEWORK_SVELTE-VITE",
      code: 1,
      documentation: "https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#sveltekit-needs-the-storybooksveltekit-framework",
      message: n.dedent`
        We've detected a SvelteKit project using the @storybook/svelte-vite framework, which is not supported.
        Please use the @storybook/sveltekit framework instead.`
    });
  }
}, M = class extends s {
  constructor(o) {
    super({
      category: "CORE-SERVER",
      code: 4,
      documentation: "",
      message: n.dedent`
        There was an exports mismatch error when trying to build Storybook.
        Please check whether the versions of your Storybook packages match whenever possible, as this might be the cause.
        
        Problematic example:
        { "@storybook/react": "7.5.3", "@storybook/react-vite": "7.4.5", "storybook": "7.3.0" }
        
        Correct example:
        { "@storybook/react": "7.5.3", "@storybook/react-vite": "7.5.3", "storybook": "7.5.3" }
        
        Please run \`npx storybook doctor\` for guidance on how to fix this issue.`
    });
    this.data = o;
  }
  static {
    r(this, "NoMatchingExportError");
  }
}, W = class extends s {
  constructor(o) {
    let c = {
      storybook: {
        helperMessage: "You can pass a --config-dir flag to tell Storybook, where your main.js file is located at.",
        documentation: "https://storybook.js.org/docs/configure"
      },
      vitest: {
        helperMessage: "You can pass a configDir plugin option to tell where your main.js file is located at.",
        // TODO: add proper docs once available
        documentation: "https://storybook.js.org/docs/configure"
      }
    }, { documentation: l, helperMessage: p } = c[o.source || "storybook"];
    super({
      category: "CORE-SERVER",
      code: 6,
      documentation: l,
      message: n.dedent`
        No configuration files have been found in your configDir: ${u.default.yellow(o.location)}.
        Storybook needs a "main.js" file, please add it.
        
        ${p}`
    });
    this.data = o;
  }
  static {
    r(this, "MainFileMissingError");
  }
}, K = class extends s {
  constructor(o) {
    let c = u.default.white(
      (o.error.stack || o.error.message).replaceAll(process.cwd(), "")
    );
    super({
      category: "CORE-SERVER",
      code: 7,
      message: n.dedent`
        Storybook couldn't evaluate your ${u.default.yellow(o.location)} file.
        
        Original error:
        ${c}`
    });
    this.data = o;
  }
  static {
    r(this, "MainFileEvaluationError");
  }
}, L = class extends s {
  constructor(o) {
    super({
      category: "CORE-SERVER",
      code: 16,
      message: `Status has typeId "${o.status.typeId}" but was added to store with typeId "${o.typeId}". Full status: ${JSON.stringify(
        o.status,
        null,
        2
      )}`
    });
    this.data = o;
  }
  static {
    r(this, "StatusTypeIdMismatchError");
  }
}, P = class extends s {
  constructor(o) {
    super({
      category: "CLI_INIT",
      code: 3,
      documentation: "",
      message: n.dedent`
        There was an error while using ${o.packageManager} to create a new ${o.projectType} project.
        
        ${o.error instanceof Error ? o.error.message : ""}`
    });
    this.data = o;
  }
  static {
    r(this, "GenerateNewProjectOnInitError");
  }
}, N = class extends s {
  constructor(o) {
    super({
      category: "CLI_UPGRADE",
      code: 3,
      message: n.dedent`
        You are trying to upgrade Storybook to a lower version than the version currently installed. This is not supported.
        
        Storybook version ${o.beforeVersion} was detected in your project, but you are trying to "upgrade" to version ${o.currentVersion}.
        
        This usually happens when running the upgrade command without a version specifier, e.g. "npx storybook upgrade".
        This will cause npm to run the globally cached storybook binary, which might be an older version.
        
        Instead you should always run the Storybook CLI with a version specifier to force npm to download the latest version:
        
        "npx storybook@latest upgrade"`
    });
    this.data = o;
  }
  static {
    r(this, "UpgradeStorybookToLowerVersionError");
  }
}, j = class extends s {
  static {
    r(this, "UpgradeStorybookUnknownCurrentVersionError");
  }
  constructor() {
    super({
      category: "CLI_UPGRADE",
      code: 5,
      message: n.dedent`
        We couldn't determine the current version of Storybook in your project.
        
        Are you running the Storybook CLI in a project without Storybook?
        It might help if you specify your Storybook config directory with the --config-dir flag.`
    });
  }
}, v = class extends s {
  static {
    r(this, "NoStatsForViteDevError");
  }
  constructor() {
    super({
      category: "BUILDER-VITE",
      code: 1,
      message: n.dedent`
        Unable to write preview stats as the Vite builder does not support stats in dev mode.
        
        Please remove the \`--stats-json\` flag when running in dev mode.`
    });
  }
}, V = class extends s {
  constructor(o) {
    super({
      category: "CLI",
      code: 1,
      message: n.dedent`
        Unable to find versions of "${o.packageName}" using ${o.packageManager}
        ${o.error && `Reason: ${o.error}`}`
    });
    this.data = o;
  }
  static {
    r(this, "FindPackageVersionsError");
  }
}, F = class extends s {
  constructor(o) {
    super({
      category: "FRAMEWORK_NEXTJS",
      code: 3,
      message: n.dedent`
        Incompatible PostCSS configuration format detected.

        Next.js uses an array-based format for plugins which is not compatible with Vite:
        
        // ❌ Incompatible format (used by Next.js)
        const config = {
          plugins: ["@tailwindcss/postcss"],
        };
        
        Please transform your PostCSS config to use the object-based format, which is compatible with Next.js and Vite:
        
        // ✅ Compatible format (works with Next.js and Vite)
        const config = {
          plugins: {
            "@tailwindcss/postcss": {},
          },
        };
        
        Original error: ${o.error.message}
      `
    });
    this.data = o;
  }
  static {
    r(this, "IncompatiblePostCssConfigError");
  }
}, $ = class extends s {
  constructor(o) {
    super({
      category: "CORE-SERVER",
      code: 1,
      message: n.dedent`
        Unable to save global settings file to ${o.filePath}
        ${o.error && `Reason: ${o.error}`}`
    });
    this.data = o;
  }
  static {
    r(this, "SavingGlobalSettingsFileError");
  }
}, B = class extends s {
  static {
    r(this, "CommonJsConfigNotSupportedError");
  }
  constructor() {
    super({
      category: "CLI_AUTOMIGRATE",
      code: 1,
      documentation: "https://storybook.js.org/docs/configure/overview#es-modules",
      message: n.dedent`
        Support for CommonJS Storybook config files has been removed in Storybook 10.0.0.
        Please migrate your config to a valid ESM file.
        
        CommonJS files (ending in .cjs, .cts, .cjsx, .ctsx) or files containing 'module.exports' are no longer supported.
        Please convert your config to use ES modules (import/export syntax).`
    });
  }
};

export {
  s as a,
  Y as b,
  y as c,
  m as d,
  E as e,
  b as f,
  R as g,
  f as h,
  h as i,
  k as j,
  A as k,
  _ as l,
  x as m,
  I as n,
  S as o,
  C as p,
  T as q,
  w as r,
  M as s,
  W as t,
  K as u,
  L as v,
  P as w,
  N as x,
  j as y,
  v as z,
  V as A,
  F as B,
  $ as C,
  B as D
};
