Skip to content

Conversation

@mfdebian
Copy link
Contributor

@mfdebian mfdebian commented Jan 9, 2026

This PR adds the missing ESM and CJS examples to their respective counterparts for the V8 documentation.

For the setFlagsFromString example, we weren't printing anything back to the user so the example looked like we just hang the terminal for one minute and then come back. So I added some events (the ones using new Array()) to add some computation that would trigger the GC so we can get some output for the example, then it showcases the actual behavior by invoking setFlagsFromString('--notrace-gc') that stops the tracing, users can see we're still creating Arrays for one more second but the GC events are now stopped via setFlagsFromString().

The same was happening for the Promise hooks example (in this case I added its CJS counterpart). We were not giving any output back to the users, so it may not be clear what it's going on, I just added the invocation of one Promise (promisePrint) so now we can see all the console.log from the Promise life cycle.

The same was also happening for the isStringOneByteRepresentation example so i just added a couple of console.log to print the buffer and see its contents.

Now all these examples give some output to users trying to understand this parts of the documentation.

There was one particular example that I couldn't make work using ESM, it's the Startup Snapshot API example, it works fine using CJS but when using ESM it throws an error, sadly I lack the V8 knowledge right now to make it work, I tested it on versions v18.20.8, v20.19.6, v22.21.1, v24.12.0 and v25.1.0

For version v18.20.8 the error is:

import fs from 'node:fs';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at main (node:internal/main/mksnapshot:130:33)
    at node:internal/main/mksnapshot:170:1

And from version v20.19.6 onwards the error is:

import fs from 'node:fs';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at minimalRunCjs (node:internal/main/mksnapshot:207:16)

I made a simple POC to reproduce the error easily here, I already asked for help in the discord but we couldn't make it work, maybe someone with better V8 expertise can help with this one.

That's it for now! Thank you and happy new year! 💚 🥳

@nodejs-github-bot nodejs-github-bot added the doc Issues and PRs related to the documentations. label Jan 9, 2026
@avivkeller avivkeller added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. doc Issues and PRs related to the documentations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants