Next.js Discord

Discord Forum

Module not found: Can't resolve 'http' on edge, and TypeError: fetch is not a function on non-edge

Unanswered
bplr posted this in #help-forum
Open in Discord
Avatar
bplrOP
Hi, i am trying to run the Weaviate vector store library using weaviate-ts-client lib but without success.
I am calling the client from the route.ts. When i config runtime edge i get "Module not found: Can't resolve 'http' " error.
When using nodejs runtime i get "TypeError: fetch is not a function".

next.config.js
--------
/** @type {import('next').NextConfig} */
//
const path = require("path");

const nextConfig = {
  output: "standalone",
  sassOptions: {
    includePaths: [path.join(__dirname, "src/app")],
  },
  images: {
    remotePatterns: [
      {
        protocol: "https",
        hostname: "learning-pizi.s3.eu-north-1.amazonaws.com",
        port: "",
        pathname: "/**",
      },
    ],
  },

  experimental: {
    outputFileTracingExcludes: ["**canvas**"],
    serverActions: true,
    serverComponentsExternalPackages: ["sequelize"],
  },
  webpack: function (config, { webpack, isServer }) {
    config.resolve.fallback = {
      fs: false,
      os: false,
      crypto: false,
      process: false,
    };
    config.resolve.alias.canvas = false;
    config.externals = [...config.externals, "canvas", "node:fs", "sequelize"];
    config.experiments = {
      asyncWebAssembly: true,
      layers: true,
      topLevelAwait: true,
    };
    config.resolve.alias = {
      ...config.resolve.alias,
      sharp$: false,
      "onnxruntime-node$": false,
    };
    config.plugins.push(
      new webpack.NormalModuleReplacementPlugin(/^node:/, (resource) => {
        resource.request = resource.request.replace(/^node:/, "");
      })
    );

    return config;
  },
};

module.exports = nextConfig;


tsconfig.json
------------
{
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts",
    "src/app/api/chat/route.ts.bkp2"
  ],
  "exclude": ["node_modules"]
}


Any idea what am i doing wrong?
Thanks for the help!

2 Replies

Avatar
!=tgt
http is a nodejs module
and thus won't work on the edge