Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

doc: add esm and cjs examples to node:v8 #61328

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

Open
mfdebian wants to merge 1 commit into nodejs:main
base: main
Choose a base branch
Loading
from mfdebian:docs-v8-esm

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

Reviewers

@lpinca lpinca lpinca approved these changes

@cjihrig cjihrig cjihrig approved these changes

@UlisesGascon UlisesGascon UlisesGascon approved these changes

@himself65 himself65 himself65 approved these changes

@avivkeller avivkeller avivkeller approved these changes

Assignees

No one assigned

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

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /