diff --git a/.changeset/strange-badgers-obey.md b/.changeset/strange-badgers-obey.md new file mode 100644 index 00000000..57788e6d --- /dev/null +++ b/.changeset/strange-badgers-obey.md @@ -0,0 +1,5 @@ +--- +"inngest": patch +--- + +Handle `chalk` being `undefined` in some environments diff --git a/packages/inngest/src/helpers/consts.ts b/packages/inngest/src/helpers/consts.ts index 0c639a7a..2d95e59d 100644 --- a/packages/inngest/src/helpers/consts.ts +++ b/packages/inngest/src/helpers/consts.ts @@ -164,7 +164,8 @@ export enum internalEvents { ScheduledTimer = "inngest/scheduled.timer", } -export const logPrefix: string = chalk.magenta.bold("[Inngest]"); +export const logPrefix: string = + chalk?.magenta.bold("[Inngest]") || "[Inngest]"; export const debugPrefix = "inngest"; diff --git a/packages/inngest/src/helpers/errors.ts b/packages/inngest/src/helpers/errors.ts index 0d6b06b0..c15d7720 100644 --- a/packages/inngest/src/helpers/errors.ts +++ b/packages/inngest/src/helpers/errors.ts @@ -405,17 +405,19 @@ export const prettyError = ({ stack, code, }: PrettyError): string => { - const { icon, colorFn } = ( + const { icon, colorFn = (s: string) => s } = ( { - error: { icon: "❌", colorFn: chalk.red }, - warn: { icon: "⚠️", colorFn: chalk.yellow }, + error: { icon: "❌", colorFn: chalk?.red }, + warn: { icon: "⚠️", colorFn: chalk?.yellow }, } satisfies Record< NonNullable, - { icon: string; colorFn: (s: string) => string } + { icon: string; colorFn?: (s: string) => string } > )[type]; - let header = `${icon} ${chalk.bold.underline(whatHappened.trim())}`; + let header = `${icon} ${ + chalk?.bold.underline(whatHappened.trim()) || whatHappened.trim() + }`; if (stack) { header += "\n" +