fix: replicate deps warning in nextjs (#1370)

This commit is contained in:
Thuc Pham
2024-10-24 09:08:04 +07:00
committed by GitHub
parent eb87b96518
commit 534d5505cb
2 changed files with 22 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"llamaindex": patch
---
fix: replicate deps warning in nextjs
+17 -5
View File
@@ -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;