Skip to content

module: improve typescript error message format #57687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

marco-ippolito
Copy link
Member

Unfortunately the automation deleted my commit #57598
TIL dont push on dep update automation or the next sunday it will be overwritten 😆

Fixes: #56830

This PR improves the error messages generated by the transpiler.

Node.js v23.9.0:

marcoippolito@marcos-MacBook-Pro node % node --input-type=commonjs-typescript -p "enum Foo"
node:internal/modules/typescript:69
        throw new ERR_INVALID_TYPESCRIPT_SYNTAX(error.message);
        ^

SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX]:   x Expected '{', got '<eof>'
   ,----
 1 | enum Foo
   :      ^^^
   `----

    at parseTypeScript (node:internal/modules/typescript:69:15)
    at processTypeScriptCode (node:internal/modules/typescript:129:42)
    at stripTypeScriptModuleTypes (node:internal/modules/typescript:196:22)
    at parseAndEvalCommonjsTypeScript (node:internal/process/execution:369:26)
    at node:internal/main/eval_string:71:3 {
  code: 'ERR_INVALID_TYPESCRIPT_SYNTAX'
}

This PR:

marcoippolito@marcos-MacBook-Pro node % ./node --input-type=commonjs-typescript -p "enum Foo"
[eval]:1   
        
     enum Foo
          ^^^
        
SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX]: Expected '{', got '<eof>'
    at parseTypeScript (node:internal/modules/typescript:71:36)
    at processTypeScriptCode (node:internal/modules/typescript:145:42)
    at stripTypeScriptModuleTypes (node:internal/modules/typescript:212:22)
    at parseAndEvalCommonjsTypeScript (node:internal/process/execution:375:26)
    at node:internal/main/eval_string:71:3 {
  code: 'ERR_INVALID_TYPESCRIPT_SYNTAX'
}

It removes the internal file path:

node:internal/modules/typescript:69
        throw new ERR_INVALID_TYPESCRIPT_SYNTAX(error.message);

Removes the padding boxing the message:

   ,----
 1 | enum Foo
   :      ^^^
   `----

In general it blends better with Node.js error style.
There is still an improvement to make that involves removing the whitespace around:

        
     enum Foo
          ^^^
  

This depends from SWC and its currently being fixed.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/security-wg
  • @nodejs/typescript

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Mar 30, 2025
@marco-ippolito marco-ippolito added the strip-types Issues or PRs related to strip-types support label Mar 30, 2025
Copy link

codecov bot commented Mar 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.23%. Comparing base (af75d04) to head (9fb2f5f).
Report is 680 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #57687   +/-   ##
=======================================
  Coverage   90.23%   90.23%           
=======================================
  Files         630      630           
  Lines      185055   185073   +18     
  Branches    36221    36221           
=======================================
+ Hits       166984   167009   +25     
+ Misses      11043    11036    -7     
  Partials     7028     7028           
Files with missing lines Coverage Δ
lib/internal/modules/typescript.js 97.51% <100.00%> (+0.17%) ⬆️
lib/internal/process/execution.js 94.81% <100.00%> (+0.02%) ⬆️

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@marco-ippolito
Copy link
Member Author

marco-ippolito commented Mar 31, 2025

Windows ofc 😫

---
duration_ms: 5506.172
exitcode: 1
severity: fail
stack: |-
  Test failure: 'the error message should not contain extra padding'
  Location: test\es-module\test-typescript-eval.mjs:268:1
  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
  + actual - expected

  + '[eval]:1   \r'
  - '[eval]:1   '
                ^

      at TestContext.<anonymous> (file:///C:/workspace/node-test-binary-windows-js-suites/node/test/es-module/test-typescript-eval.mjs:276:3)
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async Test.run (node:internal/test_runner/test:1063:7)
      at async Test.processPendingSubtests (node:internal/test_runner/test:746:7) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: '[eval]:1   \r',
    expected: '[eval]:1   ',
    operator: 'strictEqual'
  }
...

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@marco-ippolito marco-ippolito added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. labels Apr 1, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 1, 2025
@nodejs-github-bot
Copy link
Collaborator

Landed in 0d91070...1c2d98d

nodejs-github-bot added a commit that referenced this pull request Apr 1, 2025
PR-URL: #57687
Fixes: #56830
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
nodejs-github-bot pushed a commit that referenced this pull request Apr 1, 2025
PR-URL: #57687
Fixes: #56830
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
JonasBa pushed a commit to JonasBa/node that referenced this pull request Apr 11, 2025
PR-URL: nodejs#57687
Fixes: nodejs#56830
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
JonasBa pushed a commit to JonasBa/node that referenced this pull request Apr 11, 2025
PR-URL: nodejs#57687
Fixes: nodejs#56830
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
RafaelGSS pushed a commit that referenced this pull request May 1, 2025
PR-URL: #57687
Fixes: #56830
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
RafaelGSS pushed a commit that referenced this pull request May 1, 2025
PR-URL: #57687
Fixes: #56830
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
RafaelGSS pushed a commit that referenced this pull request May 2, 2025
PR-URL: #57687
Fixes: #56830
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
RafaelGSS pushed a commit that referenced this pull request May 2, 2025
PR-URL: #57687
Fixes: #56830
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
@marco-ippolito marco-ippolito added the backport-open-v22.x Indicate that the PR has an open backport label Jun 25, 2025
marco-ippolito added a commit to marco-ippolito/node that referenced this pull request Jun 25, 2025
PR-URL: nodejs#57687
Fixes: nodejs#56830
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
marco-ippolito pushed a commit to marco-ippolito/node that referenced this pull request Jun 25, 2025
PR-URL: nodejs#57687
Fixes: nodejs#56830
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-open-v22.x Indicate that the PR has an open backport commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. strip-types Issues or PRs related to strip-types support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide more information when there is a SyntaxError
5 participants