Give more specific errors for verbatimModuleSyntax#62113
Merged
DanielRosenwasser merged 4 commits intomainfrom Jul 23, 2025
Merged
Give more specific errors for verbatimModuleSyntax#62113DanielRosenwasser merged 4 commits intomainfrom
verbatimModuleSyntax#62113DanielRosenwasser merged 4 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves error messages for the verbatimModuleSyntax TypeScript compiler option to provide more specific and actionable guidance to developers. The change replaces generic "ESM syntax is not allowed" messages with detailed explanations that include specific configuration suggestions.
Key Changes
- Replaces generic TS1286 error message with a new, more detailed TS1295 error message for
verbatimModuleSyntaxviolations - Adds conditional logic to provide different error messages based on file extensions (.cts/.cjs vs other files)
- Updates error message for
module: preservemode to be more descriptive
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/compiler/diagnosticMessages.json | Adds new detailed error message (TS1295) and updates existing messages to be more specific |
| src/compiler/checker.ts | Implements logic to conditionally show different error messages based on file type and adds helper function |
| tests/baselines/reference/*.errors.txt | Updates test baselines to reflect the new, more detailed error messages |
src/compiler/checker.ts
Outdated
| // Check if the file is .cts or .cjs (CommonJS-specific extensions) | ||
| if (fileExtensionIsOneOf(fileName, [Extension.Cts, Extension.Cjs])) { | ||
| return Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax; | ||
| } else { |
There was a problem hiding this comment.
The error message for .cts/.cjs files should provide guidance on how to resolve the issue, similar to the detailed message used for other file types. Currently it only states what's wrong without offering solutions.
Suggested change
| } else { | |
| if (fileExtensionIsOneOf(fileName, [Extension.Cts, Extension.Cjs])) { | |
| return Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax_Adjust_the_type_field_in_the_nearest_package_json_to_make_this_file_an_ECMAScript_module_or_adjust_your_verbatimModuleSyntax_module_and_moduleResolution_settings_in_TypeScript; | |
| } else { |
RyanCavanaugh
approved these changes
Jul 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Especially given that
tsc --initinitializes with VMS.