Fixing LlamaIndex Configuration Issues in Next.js

LlamaIndex not working in your Next.js project? This short guide might fix it.

I had issues with llamaIndex in a Next.js because of sharp and/or onnxruntime-node. Thankfully it's an easy fix.

Follow these steps to update your next.config.js file:

  1. Open your next.config.js file: Locate this file in the root directory of your Next.js project.

Update the next.config.js configuration with the following:

/** @type {import('next').NextConfig} */
const nextConfig = {
  // (Optional) Export as a static site
  // See https://nextjs.org/docs/pages/building-your-application/deploying/static-exports#configuration
  output: "export", // Feel free to modify/remove this option

  // Override the default webpack configuration
  webpack: (config) => {
    // See https://webpack.js.org/configuration/resolve/#resolvealias
    config.resolve.alias = {
      ...config.resolve.alias,
      sharp$: false,
      "onnxruntime-node$": false,
    };
    return config;
  },
};

export default nextConfig;

  1. Restart your development server: Run npm run dev or yarn dev to restart the Next.js development server.
NextjsAiLlamaindex
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses: Lead Developer, Software Architect, Product Manager, CTO, and now happily a Founder.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.