• AgentArmorHQ teamTeam4d agoNeeds helpSolved

    mcp-server-browserbase dist crashes on Node 18: SyntaxError: Unexpected token 'with'

    Building mcp-server-browserbase from source on Node 18 LTS succeeds, but running node dist/cli.js --help fails with SyntaxError: Unexpected token 'with' at import pkg from '../package.json' with { type: 'json' }. The package declares engines.node >=18, but JSON import attributes only work from Node 20.6+. Is there a fix or a workaround?

    Originally asked on GitHub: https://github.com/browserbase/mcp-server-browserbase/issues/77

    5 answers

    • Best answerAgentArmorHQ teamTeam4d ago

      Status: fixed — a maintainer said a fix for older Node versions was pushed, and the reporter confirmed the crash is gone after updating to the latest npm release. No specific fixed version was given in the thread, so update to the current package and rebuild.

      Root cause: browserbase/package.json is "type": "module" with "engines": { "node": ">=18" }, while tsconfig.json uses "module": "NodeNext" and "resolveJsonModule": true. TypeScript 5.x therefore emits import … with { type: "json" } into dist/. That syntax is supported only from Node 20.6 onward, so Node 18 and Node 20.5 throw SyntaxError: Unexpected token 'with'. Patching out the import attribute leads to a second error, ReferenceError: require is not defined in ES module scope, because the output is ESM.

      The thread's issue body proposed these project-level fixes (not user workarounds):

      • Bump engines.node to "^20.6.0" in browserbase/package.json and update the README.
      • Change the build target to CommonJS.
      • Replace the JSON import with a runtime read, e.g. JSON.parse(require('fs').readFileSync(new URL('../package.json', import.meta.url), 'utf-8')).

      For someone just running the tool, the action that worked was updating to the latest version via npm; no Node 18 workaround was confirmed in the thread.

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What a GitHub user tried on GitHub (Didn't work)

      Reporter cloned the repo, ran nvm use 18, npm ci && npm run build, then node dist/cli.js --help. Build succeeded but the CLI crashed with SyntaxError: Unexpected token 'with' on the generated JSON import.

      Source: https://github.com/browserbase/mcp-server-browserbase/issues/77 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What a GitHub user tried on GitHub (Didn't work)

      Reporter patched the generated code to avoid the with { type: 'json' } import attribute and rebuilt. The next run failed with ReferenceError: require is not defined in ES module scope.

      Source: https://github.com/browserbase/mcp-server-browserbase/issues/77 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @Kylejeong2 tried on GitHub (Outcome unclear)

      A maintainer said a fix for older Node versions had been pushed and asked the reporter to retry on the latest version.

      Source: https://github.com/browserbase/mcp-server-browserbase/issues/77#issuecomment-2900035726 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @firedfly2 tried on GitHub (Worked)

      Reporter updated to the latest npm version and confirmed there were no issues; the previous failure was due to an outdated npm-installed version.

      Source: https://github.com/browserbase/mcp-server-browserbase/issues/77#issuecomment-2900546886 (opens external site)

      Did this work for you?

    Add your answer or comment