Skip to content

Build succeeds but generated dist crashes on Node 18 — import … with { type: "json" } requires Node 20.6 + #77

Open
@firedfly2

Description

@firedfly2

What happened?

  1. git clone https://github.com/browserbase/mcp-server-browserbase.git
  2. cd mcp-server-browserbase/browserbase
  3. nvm use 18 # or any Node 18.x LTS
  4. npm ci && npm run build
  5. node dist/cli.js --help

The TypeScript compilation itself succeeds, but the generated JS immediately throws:

file:///…/browserbase/dist/program.js:6
import pkg from '../package.json' with { type: 'json' };
                              ^^^^
SyntaxError: Unexpected token 'with'

If I patch that to avoid the import‑assertion and rebuild, the next run crashes with:

ReferenceError: require is not defined in ES module scope

Why this happens

  • tsconfig.json is configured with "module": "NodeNext" + "resolveJsonModule": true.
    TypeScript 5.x therefore emits import … with { type: "json" } into dist/.
  • package.json declares "type": "module" and "engines": { "node": ">=18" }, so runtime is ESM but promises only Node ≥ 18.
  • JSON‑import assertions are officially supported only from Node 20.6 onward, so Node 18 LTS cannot execute the output.

Expected behaviour

Either…

  • the project advertises “requires Node 20.6+” (update package.json engines and README), or
  • the build emits code that is runnable on Node 18 (e.g. change module to "CommonJS" or read package.json via fs.readFileSync).

Repro matrix

Node version npm run build node dist/…
18.x LTS ✅ succeeds ❌ SyntaxError (with { type: 'json' })
20.5 ❌ same as above
20.6 + ✅ runs

Suggested fix

  • Quick: bump "engines.node" in browserbase/package.json to "^20.6.0" and mention in README.
  • Long‑term: if Node 18 support is desired, change build target to CommonJS or replace the JSON import with:
JSON.parse(
  require('fs').readFileSync(
    new URL('../package.json', import.meta.url),
    'utf-8'
  )
);

Thanks for the great project!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions