You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: Node 22 compatibility for source maps and import assertions - #5503
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
> [email protected] 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
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!
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!
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!
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
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.
Node 22 sets its own internal
Error.prepareStackTracehandler (ErrorPrepareStackTrace) before any user code runs, which broke CoffeeScript in three ways.register.jssaw a truthyError.prepareStackTraceand skipped callingpatchStackTrace(), so CoffeeScript's source-map translator was never installed. Stack traces reported raw JS line numbers instead of original CoffeeScript line numbers, breaking tests#4418and#4558.The dynamic
import()assert: { type: 'json' }syntax was removed in Node 22 withERR_IMPORT_ATTRIBUTE_MISSING. Replaced with the currentwith: { type: 'json' }syntax intest/import_assertions.coffee.The test
"requiring 'CoffeeScript' doesn't change Error.prepareStackTrace"expectedError.prepareStackTrace === undefinedin a fresh Node process, which is no longer true on Node 22 since Node pre sets it internally. Updated the assertion to check that requiringcoffeescript.jsleaves it unchanged, which is the correct invariant.src/register.coffeeandlib/coffeescript/register.jsare updated to detect and ignore Node's own internal handler sopatchStackTrace()installs correctly.test/import_assertions.coffeereplacesassert:withwith:in two dynamicimport()calls.test/sourcemap.coffeechecks thatprepareStackTraceis unchanged rather than undefined.Test result(Before):
Test result (After):