To deploy a NextJS with BAML, take a look at the starter template: https://github.com/BoundaryML/baml-examples/tree/main/nextjs-starter

All you need is to modify the nextjs.config.mjs to allow BAML to run properly:

1/** @type {import('next').NextConfig} */
2const nextConfig = {
3 experimental: {
4 serverComponentsExternalPackages: ["@boundaryml/baml"],
5 },
6 webpack: (config, { dev, isServer, webpack, nextRuntime }) => {
7 config.module.rules.push({
8 test: /\.node$/,
9 use: [
10 {
11 loader: "nextjs-node-loader",
12 options: {
13 outputPath: config.output.path,
14 },
15 },
16 ],
17 });
18
19 return config;
20 },
21};
22
23export default nextConfig;

and change your package.json to build the baml client automatically (and enable logging in dev mode if you want):

1 "scripts": {
2 "dev": "BAML_LOG=info next dev",
3 "build": "pnpm generate && next build",
4 "start": "next start",
5 "lint": "next lint",
6 "generate": "baml-cli generate --from ./baml_src"
7 },