Skip to content

Top-level await in Node cell causes syntax error with Node 22 #91

@mootari

Description

@mootari

The Node example in the data-loaders docs includes a top-level await. The docs further mention Node.js 22.12+ as minimum version.

However, with Node 22 LTS a top-level await will cause a syntax error for me, both during kit builds and in Desktop. Both succeed only after I switch to Node 24. I manage Node via fnm and put it at one of notebook-kit's search paths via

fnm use 22
sudo ln -sf $(which node) /usr/local/bin/node

It may be worth mentioning that I can run this repo's docs:build script (which in turn uses tsx) without errors.

Example

index.html:

<!doctype html>
<notebook theme="air">
  <title>Untitled</title>
  <script type="application/vnd.node.javascript" output="test" format="text">
    process.stdout.write(await Date.now().toString())
  </script>
  <script type="module">
    test
  </script>
</notebook>
% npx notebooks build index.html
vite v7.1.6 building for production...
[stdin]:1
process.stdout.write(await Date.now().toString())
                     ^^^^^

SyntaxError: missing ) after argument list
    at makeContextifyScript (node:internal/vm:185:14)
    at compileScript (node:internal/process/execution:386:10)
    at node:internal/process/execution:450:25
    at [stdin]-wrapper:6:24
    at runScriptInContext (node:internal/process/execution:447:60)
    at evalFunction (node:internal/process/execution:87:30)
    at evalScript (node:internal/process/execution:99:3)
    at node:internal/main/eval_stdin:53:5
    at Socket.<anonymous> (node:internal/process/execution:200:5)
    at Socket.emit (node:events:530:35)

Node.js v22.17.0
✓ 165 modules transformed.

Please note that the build still finishes with exit code 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions