Handle TS7 @typescript-eslint config crashes in plugin-kit import validation#1561
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: f0c4595 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@typescript-eslint config crashes in plugin-kit import validation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f0c4595. Configure here.
| overrideConfig: eslintConfig, | ||
| }) | ||
| results = await fallbackEslint.lintFiles([path.join(basePath, '**/*.{js,jsx,ts,tsx}')]) | ||
| } |
There was a problem hiding this comment.
Fallback skips unparseable TypeScript
Medium Severity
When the TS7 @typescript-eslint retry runs, ESLint uses the default Espree parser (no TypeScript parser in overrideConfig). Typical plugin .ts/.tsx files then fail parsing, and the pipeline keeps only no-restricted-imports messages and drops files with none—so restricted imports in those files can go unreported while validateImports still returns success.
Reviewed by Cursor Bugbot for commit f0c4595. Configure here.
There was a problem hiding this comment.
Pull request overview
This PR updates @sanity/plugin-kit’s import validation to avoid crashing verify-package / verify-studio when ESLint initialization fails due to a TypeScript 7 + @typescript-eslint config runtime error, by retrying linting with user config disabled.
Changes:
- Extracts the shared
no-restricted-importsoverride config into a reusableeslintConfigobject (and adds basicparserOptions). - Adds a targeted fallback retry (
useEslintrc: false) when ESLint throws a specific@typescript-eslint/"reading 'Cjs'"crash signature. - Adds a patch changeset for
@sanity/plugin-kit.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/@sanity/plugin-kit/src/dependencies/import-linter.ts | Adds an ESLint fallback path for TS7 @typescript-eslint config crashes during import validation. |
| .changeset/green-stingrays-dress.md | Records a patch release note for the import-check fallback behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let results | ||
| try { | ||
| results = await eslint.lintFiles([path.join(basePath, '**/*.{js,jsx,ts,tsx}')]) | ||
| } catch (error) { | ||
| const message = error instanceof Error ? error.message : String(error) | ||
| const shouldRetryWithoutUserConfig = | ||
| message.includes('@typescript-eslint') && message.includes("reading 'Cjs'") | ||
|
|
||
| if (!shouldRetryWithoutUserConfig) { | ||
| throw error | ||
| } | ||
|
|
||
| log.debug('Retrying ESLint import check without user config: %s', message) | ||
| const fallbackEslint = new ESLint({ | ||
| cwd: basePath, | ||
| useEslintrc: false, | ||
| overrideConfig: eslintConfig, | ||
| }) | ||
| results = await fallbackEslint.lintFiles([path.join(basePath, '**/*.{js,jsx,ts,tsx}')]) | ||
| } | ||
|
|


The CI
testjob was failing in@sanity/plugin-kitbecauseverify-package/verify-studioimport checks crashed when ESLint loaded project config under TypeScript 7 (@typescript-eslintCjsruntime error). This change keeps import validation functional by falling back to a config-isolated ESLint run for that failure mode.Root issue addressed
validateImports()aborted on ESLint initialization/runtime errors caused by upstream TS7 +@typescript-eslintconfig loading behavior.Behavior change in import validation
@typescript-eslint+reading 'Cjs'), retry linting with:useEslintrc: falseno-restricted-importsrulesecmaVersion: 'latest',sourceType: 'module')Release metadata
@sanity/plugin-kit.Note
Low Risk
Narrow fallback only on a known TS7 ESLint crash signature; default lint path and import rules are unchanged.
Overview
validateImportsin@sanity/plugin-kitno longer fails outright when ESLint blows up loading project config under TypeScript 7 (@typescript-eslint/reading 'Cjs'). That crash was breakingverify-packageandverify-studioimport validation in CI.The shared
no-restricted-importsoverride is extracted and now includes explicitparserOptions(ecmaVersion: 'latest',sourceType: 'module'). On that specific error, linting retries withuseEslintrc: falseand the same override so Sanity v2 import rules still run without loading broken user ESLint config.A patch changeset records the
@sanity/plugin-kitrelease note.Reviewed by Cursor Bugbot for commit f0c4595. Bugbot is set up for automated code reviews on this repo. Configure here.