Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

manually build pg nextjs-edge #3

Closed
xucongyong opened this issue Jan 13, 2025 · 1 comment
Closed

manually build pg nextjs-edge #3

xucongyong opened this issue Jan 13, 2025 · 1 comment

Comments

@xucongyong
Copy link

i copy mre-pg-nextjs-edge file to my project code,
but have error

next.config.mjs

import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev';
import createNextIntlPlugin from 'next-intl/plugin';
const withNextIntl = createNextIntlPlugin();

// Here we use the @cloudflare/next-on-pages next-dev module to allow us to use bindings during local development
// (when running the application with `next dev`), for more information see:
// https://github.com/cloudflare/next-on-pages/blob/main/internal-packages/next-dev/README.md
if (process.env.NODE_ENV === 'development') {
  await setupDevPlatform();
}

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  webpack: (config, { nextRuntime }) => {
    config.externals.push({
      // Prevent compilation failure under Next.js build (`next build`):
      // `Module build failed: UnhandledSchemeError: Reading from "cloudflare:sockets" is not handled by plugins (Unhandled scheme)`
      "cloudflare:sockets": "commonjs cloudflare:sockets",
    });

    if (nextRuntime === "edge") {
      // expose access to Node.js `net` module within Next.js Edge runtime local sandbox
      // same as Next.js does for `node:buffer`, `node:async_hooks` etc
      // - https://github.com/vercel/next.js/blob/6185444e0a944a82e7719ac37dad8becfed86acd/packages/next/src/build/webpack/plugins/middleware-plugin.ts#L833
      config.externals.unshift({
        net: "commonjs node:net",
        "node:net": "commonjs node:net",
      });
    }

    return config;
  },
};
export default withNextIntl(nextConfig);

error:

./node_modules/pgpass/lib/helper.js:4:1
Module not found: Can't resolve 'stream'
  2 |
  3 | var path = require('path')
> 4 |   , Stream = require('stream').Stream
    | ^
  5 |   , split = require('split2')
  6 |   , util = require('util')
  7 |   , defaultPort = 5432

how to manually build pg nextjs-edge?

thank you andyjy

@andyjy
Copy link
Owner

andyjy commented Jan 13, 2025

hi @xucongyong this repo was an example attempting to reproduce how to patch node-postgres to run under Next.js edge runtime, but I realised it's not possible.

@andyjy andyjy closed this as completed Jan 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants