diff --git a/.changeset/funny-drinks-argue.md b/.changeset/funny-drinks-argue.md new file mode 100644 index 0000000000000000000000000000000000000000..14fd2495ea65661c6576c78932775a6abf1db20d --- /dev/null +++ b/.changeset/funny-drinks-argue.md @@ -0,0 +1,5 @@ +--- +"llamaindex": patch +--- + +fix: replicate deps warning in nextjs diff --git a/packages/llamaindex/src/next.ts b/packages/llamaindex/src/next.ts index 8e44e479c1f33a4598ea4379b375dd0889f527b3..e72541648c3bb25362d2fc23410946ecf4e506f7 100644 --- a/packages/llamaindex/src/next.ts +++ b/packages/llamaindex/src/next.ts @@ -24,7 +24,7 @@ export default function withLlamaIndex(config: any) { "@xenova/transformers", ); const userWebpack = config.webpack; - config.webpack = function (webpackConfig: any) { + config.webpack = function (webpackConfig: any, options: any) { if (userWebpack) { webpackConfig = userWebpack(webpackConfig); } @@ -32,14 +32,26 @@ export default function withLlamaIndex(config: any) { ...webpackConfig.resolve.alias, "@google-cloud/vertexai": false, }; + + // Disable modules that are not supported in vercel edge runtime + if (options?.nextRuntime === "edge") { + webpackConfig.resolve.alias["replicate"] = false; + } + // Following lines will fix issues with onnxruntime-node when using pnpm // See: https://github.com/vercel/next.js/issues/43433 - webpackConfig.externals.push({ + const externals: Record<string, string> = { "onnxruntime-node": "commonjs onnxruntime-node", sharp: "commonjs sharp", - chromadb: "commonjs chromadb", - unpdf: "commonjs unpdf", - }); + chromadb: "chromadb", + unpdf: "unpdf", + }; + + if (options?.nextRuntime === "nodejs") { + externals.replicate = "commonjs replicate"; + } + + webpackConfig.externals.push(externals); return webpackConfig; }; return config;