Skip to content

Commit

Permalink
fix(nextjs-plugin): issue with external baml not getting loaded
Browse files Browse the repository at this point in the history
correctly
  • Loading branch information
seawatts committed Jan 22, 2025
1 parent 8da2690 commit cbd5b12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 50 deletions.
49 changes: 1 addition & 48 deletions integ-tests/react/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,6 @@ import { withBaml } from "@boundaryml/baml-nextjs-plugin";
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
// serverExternalPackages: ["@boundaryml/baml", "@boundaryml/baml-darwin-arm64"],
// webpack: (config, { dev, isServer, webpack, nextRuntime }) => {
// // Handle native modules
// if (isServer) {
// // Externalize the native module
// config.externals = [
// ...(Array.isArray(config.externals) ? config.externals : []),
// '@boundaryml/baml-darwin-arm64',
// '@boundaryml/baml',
// ];
// }

// if (!isServer) {
// // Prevent client-side loading of native modules
// config.resolve.fallback = {
// ...config.resolve?.fallback,
// '@boundaryml/baml-darwin-arm64': false,
// '@boundaryml/baml': false,
// };
// }

// config.module = config.module || { rules: [] };
// config.module.rules.push({
// test: /\.node$/,
// use: [
// {
// loader: "nextjs-node-loader",
// options: {
// flags: 'binding',
// outputPath: config.output?.path,
// },
// },
// ],
// });

// // Ensure native addons are processed correctly
// config.resolve = config.resolve || {};
// config.resolve.alias = {
// ...config.resolve.alias,
// "@boundaryml/baml-darwin-arm64": require.resolve("@boundaryml/baml-darwin-arm64"),
// };

// return config;
// },
};

const configWithBaml = withBaml()(nextConfig);

export default configWithBaml;
export default withBaml()(nextConfig);
12 changes: 10 additions & 2 deletions typescript/nextjs-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ export function withBaml(bamlConfig: BamlNextConfig = {}) {
? {
serverExternalPackages: [
...((nextConfig as any)?.serverExternalPackages || []),
"@boundaryml/baml"
"@boundaryml/baml",
],
}
: {
experimental: {
...nextConfig.experimental,
serverComponentsExternalPackages: [
...((nextConfig.experimental as any)?.serverComponentsExternalPackages || []),
"@boundaryml/baml"
"@boundaryml/baml",
],
},
}),
Expand All @@ -65,6 +65,14 @@ export function withBaml(bamlConfig: BamlNextConfig = {}) {
config = bamlConfig.webpack(config, context);
}

if (context.isServer) {
// Externalize the native module
config.externals = [
...(Array.isArray(config.externals) ? config.externals : []),
'@boundaryml/baml',
];
}

config.module = config.module || {};
config.module.rules = config.module.rules || [];
config.module.rules.push({
Expand Down

0 comments on commit cbd5b12

Please sign in to comment.