https://www.boundaryml.com logo
🟡 BAML Module Export Error in TypeScript
# questions
s
Hello Team, I am getting the following error.
async_request.ts:22  Uncaught SyntaxError: The requested module '/node_modules/@boundaryml/baml/index.js?v=ad07a5db' does not provide an export named 'HTTPRequest' (at async_request.ts:22:23)
I am new to using BAML with typescript and web dev. Any help would be appreciated. What I have already tried - - Downgrading to 206.1 - Deleting and regenerating files - changing the generator to include ESM - restarting the server (many times) - clearing cache https://cdn.discordapp.com/attachments/1253172394345107466/1418579853745193043/image.png?ex=68cea2f1&is=68cd5171&hm=563b25dd1b90c7748846a4fa6788b4273e63dc39a15b59b45834b776662a63af&
a
Interesting, ill take a look and patch asap
v
Ah yes! Httpresponse should be import type
a
Ah yeah
Import {type HttpRequest}
we will fix it
v
I've got this! thanks for flagging this @sjz3904
s
Hello, I manually tried to patch the generated files. But there are lot more of these type import fixes (ThrowIfVersionMismatch, BamlAbortError, BamlStream, Collector, toBamlError, BamlCtxManager) that were needed across different files and I finally ended up with following error.
Copy code
globals.ts:25  Uncaught ReferenceError: process is not defined
    at globals.ts:25:13
https://cdn.discordapp.com/attachments/1418579854714212403/1418806392529096814/image.png?ex=68cf75ec&is=68ce246c&hm=aa64e9ac2265ede9d9d49e418aad2b6243a39dec7bb58400b2ea831bdc805fa7&
v
hmm, can you share how you've set up typechecking?
I can try and repro it
(working on type code-gen atm)
v
thanks! I'll check and seee what i get
is this bun or node btw?
s
node
v
thanks!
a
this config in our typescript-esm integ test package emulates the same errors:
Copy code
{
  "extends": "@tsconfig/node23/tsconfig.json",
  "exclude": [
    "dist"
  ],
  "compilerOptions": {
    "outDir": "dist",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "allowSyntheticDefaultImports": false,
    "esModuleInterop": false
  }
}
the problem is the native imports are not esm compatible, and if we add --esm to the napi build script, and only support esm i think that may be the way to go.
perhaps they need to add esModuleInterop: true potentially
v
there should be! this is good for flagging
we have tests that ensure we work on esm, but we don't yet work directly on frontend. If you get a small repro repo, would be happy to take a stab and figure out why this happend
Copy code
ReferenceError: __filename is not defined in ES module scope
    at file:///var/task/chunks/_/baml_client-BqK7FfZN.mjs:4:26
    ... 8 lines matching cause stack trace ...
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26) {
  cause: ReferenceError: __filename is not defined in ES module scope
      at file:///var/task/chunks/_/baml_client-BqK7FfZN.mjs:4:26
      at file:///var/task/chunks/_/rolldown-runtime.mjs:3:48
      at file:///var/task/chunks/_/baml_client-BqK7FfZN.mjs:378:17
      at file:///var/task/chunks/_/rolldown-runtime.mjs:3:48
      at file:///var/task/chunks/_/baml_client-BqK7FfZN.mjs:847:15
      at file:///var/task/chunks/_/rolldown-runtime.mjs:3:48
      at file:///var/task/chunks/_/baml_client-BqK7FfZN.mjs:988:5
      at ModuleJob.run (node:internal/modules/esm/module_job:345:25)
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26),
  status: 500,
  statusText: undefined,
  headers: undefined,
  data: undefined,
  body: undefined,
  unhandled: true
}
@Vaibhav (BAML 🐑) please check
## ✅ This Branch: Bun Runtime Workaround Branch:
test/bun-runtime
This branch demonstrates that using Bun runtime instead of Node.js avoids the ESM
__filename
error. ### Why Bun Works Bun provides built-in compatibility for CommonJS globals (
__filename
,
__dirname
,
require
) in ESM modules, unlike Node.js which strictly enforces ESM semantics. ### How to Use ```bash # Clone this branch git clone -b test/bun-runtime https://github.com/Haoxincode/vercel-baml-esm-error.git cd vercel-baml-esm-error # Install & build with Bun bun install bun run build # Run - NO ERROR! bun run start Vercel Deployment This branch includes vercel.json configured with Bun runtime: { "bunVersion": "1.x" } Deploy this branch to Vercel and it should work without the ESM error.
v
thankyou for the repro here, we hsould be able to take it from here as a friday project!! 🙂