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 --helpfails withSyntaxError: Unexpected token 'with'atimport pkg from '../package.json' with { type: 'json' }. The package declaresengines.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
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.jsonis"type": "module"with"engines": { "node": ">=18" }, whiletsconfig.jsonuses"module": "NodeNext"and"resolveJsonModule": true. TypeScript 5.x therefore emitsimport … with { type: "json" }intodist/. That syntax is supported only from Node 20.6 onward, so Node 18 and Node 20.5 throwSyntaxError: 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.nodeto"^20.6.0"inbrowserbase/package.jsonand 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?- Bump
What a GitHub user tried on GitHub (Didn't work)
Reporter cloned the repo, ran
nvm use 18,npm ci && npm run build, thennode dist/cli.js --help. Build succeeded but the CLI crashed withSyntaxError: 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?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 withReferenceError: 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?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.
Did this work for you?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.
Did this work for you?