Skip to content

fix(cli): guard importAlias type before string operations - #2238

Draft
okxint wants to merge 1 commit into
t3-oss:mainfrom
okxint:fix/import-alias-crash
Draft

fix(cli): guard importAlias type before string operations#2238
okxint wants to merge 1 commit into
t3-oss:mainfrom
okxint:fix/import-alias-crash

Conversation

@okxint

@okxint okxint commented Jul 4, 2026

Copy link
Copy Markdown

What

Fixes a TypeError crash when --import-alias is passed without a value in CI mode (--CI).

Root cause

--import-alias is declared as [alias] (optional value) in Commander. When passed bare with --CI, Commander coerces it to the boolean true instead of a string. The CI path skips the interactive prompt, so importAlias stays as true. Downstream:

  • index.ts compares importAlias !== "~/"true !== "~/" passes, so the invalid value flows through
  • setImportAlias.ts calls .replace() on it → TypeError: Cannot read properties of undefined

Fix

Two defensive guards:

// cli/src/index.ts
- if (importAlias !== "~/") {
+ if (typeof importAlias === "string" && importAlias !== "~/") {

// cli/src/helpers/setImportAlias.ts
  export const setImportAlias = (projectDir: string, importAlias: string) => {
+   if (typeof importAlias !== "string") return;

Fixes #2215

…rror

When --import-alias is passed without a value in CI mode, Commander sets
the option to true (boolean) instead of a string. The subsequent .replace()
calls on a non-string value crash with TypeError. Add typeof guards in both
index.ts and setImportAlias.ts to handle this safely.

Fixes t3-oss#2215
@changeset-bot

changeset-bot Bot commented Jul 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6971f61

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
create-t3-app Ready Ready Preview, Comment Jul 4, 2026 5:31am

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: --import-alias flag crashes with TypeError when used in CI mode

1 participant