Skip to content

fix: Node 22 compatibility for source maps and import assertions - #5503

Merged
GeoffreyBooth merged 7 commits into
jashkenas:mainfrom
abhayagarwal-dev:fix/node22-compat
Oct 20, 2026
Merged

GeoffreyBooth merged 7 commits into
jashkenas:mainfrom
abhayagarwal-dev:fix/node22-compat

Conversation

@abhayagarwal-dev

Copy link
Copy Markdown
Contributor

Node 22 sets its own internal Error.prepareStackTrace handler (ErrorPrepareStackTrace) before any user code runs, which broke CoffeeScript in three ways.

register.js saw a truthy Error.prepareStackTrace and skipped calling patchStackTrace(), so CoffeeScript's source-map translator was never installed. Stack traces reported raw JS line numbers instead of original CoffeeScript line numbers, breaking tests #4418 and #4558.

The dynamic import() assert: { type: 'json' } syntax was removed in Node 22 with ERR_IMPORT_ATTRIBUTE_MISSING. Replaced with the current with: { type: 'json' } syntax in test/import_assertions.coffee.

The test "requiring 'CoffeeScript' doesn't change Error.prepareStackTrace" expected Error.prepareStackTrace === undefined in a fresh Node process, which is no longer true on Node 22 since Node pre sets it internally. Updated the assertion to check that requiring coffeescript.js leaves it unchanged, which is the correct invariant.

src/register.coffee and lib/coffeescript/register.js are updated to detect and ignore Node's own internal handler so patchStackTrace() installs correctly. test/import_assertions.coffee replaces assert: with with: in two dynamic import() calls. test/sourcemap.coffee checks that prepareStackTrace is unchanged rather than undefined.

Test result(Before):

  #4418: stack traces for compiled files reference the correct line number
  AssertionError [ERR_ASSERTION]: Expected 7 to equal 3

  #4418: stack traces for compiled strings reference the correct line number
  AssertionError [ERR_ASSERTION]: Expected 7 to equal 3

  #4558: compiling a string inside a script doesn't screw up stack trace line number
  TypeError: Cannot read properties of null (reading '1')

  dynamic import assertion
  TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "data:application/json,{"ofLife":42}" needs an import attribute of "type: json"

  assert keyword
  TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "data:application/json,{"thatIAm":42}" needs an import attribute of "type: json"

failed 5 and passed 1456 tests in 8.09 seconds

Test result (After):

$npm test

> coffeescript@2.7.0 test
> node ./bin/cake test

Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
passed 1473 tests in 8.33 seconds 

@abhayagarwal-dev

Copy link
Copy Markdown
Contributor Author

@GeoffreyBooth could you please trigger the workflow on this PR when you get time? Thank you!

@abhayagarwal-dev

Copy link
Copy Markdown
Contributor Author

I noticed the CI build failed with "Error: Unable to find Node version '12.x' for platform darwin and architecture arm64," and the remaining jobs were canceled due to the initial failure. The changes in this PR update dynamic imports to standard with: { type: 'json' } syntax and ensure CoffeeScript handles Node 22+'s default ErrorPrepareStackTrace, which I have verified passes all 1,473 tests under Node.js CITGM on Node 22+. Please let me know if you have any feedback on this PR or if anything else is needed to get it merged!

GeoffreyBooth and others added 5 commits October 8, 2026 18:02
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@abhayagarwal-dev

abhayagarwal-dev commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @GeoffreyBooth, I've pushed an update to Cakefile adding the Chrome executable path for Windows CI in test:browser and updating the skipUnless feature check from assert: to with: for Node 24+ compatibility. Can you trigger workflow to verify the changes?
Thank you!

@abhayagarwal-dev

Copy link
Copy Markdown
Contributor Author

Hi @GeoffreyBooth, just a gentle check-in on this PR.
Please let me know if you have any feedback on this PR or if anything else is needed to get it merged!

@GeoffreyBooth
GeoffreyBooth merged commit 4aaa755 into jashkenas:main Oct 20, 2026
18 checks passed
@GeoffreyBooth GeoffreyBooth mentioned this pull request Oct 24, 2026
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.

2 participants