From 534d5505cb01aa1f8dcaa6ee79ec8a71d0e3c2cd Mon Sep 17 00:00:00 2001 From: Thuc Pham <51660321+thucpn@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:08:04 +0700 Subject: [PATCH] fix: replicate deps warning in nextjs (#1370) --- .changeset/funny-drinks-argue.md | 5 +++++ packages/llamaindex/src/next.ts | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 .changeset/funny-drinks-argue.md diff --git a/.changeset/funny-drinks-argue.md b/.changeset/funny-drinks-argue.md new file mode 100644 index 000000000..14fd2495e --- /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 8e44e479c..e72541648 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; -- GitLab