Next.js Discord

Discord Forum

Can't resolve react-server-dom-webpack in Next 14.0.1?

Answered
Griffon Nivernais posted this in #help-forum
Open in Discord
Griffon NivernaisOP
Stuck with this error when using react-pdf but can't seem to break out of it, even using a version of my application that worked perfectly fine.
Module not found: Can't resolve 'react-server-dom-webpack/client'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/.pnpm/next@14.1.3_@babel+core@7.24.0_react-dom@18.2.0_react@18.2.0_sass@1.69.5/node_modules/next/dist/client/components/router-reducer/router-reducer.js
./node_modules/.pnpm/next@14.1.3_@babel+core@7.24.0_react-dom@18.2.0_react@18.2.0_sass@1.69.5/node_modules/next/dist/shared/lib/router/action-queue.js
./node_modules/.pnpm/next@14.1.3_@babel+core@7.24.0_react-dom@18.2.0_react@18.2.0_sass@1.69.5/node_modules/next/dist/client/components/use-reducer-with-devtools.js
./node_modules/.pnpm/next@14.1.3_@babel+core@7.24.0_react-dom@18.2.0_react@18.2.0_sass@1.69.5/node_modules/next/dist/client/components/app-router.js
./node_modules/.pnpm/next@14.1.3_@babel+core@7.24.0_react-dom@18.2.0_react@18.2.0_sass@1.69.5/node_modules/next/dist/client/app-call-server.js
./node_modules/.pnpm/next@14.1.3_@babel+core@7.24.0_react-dom@18.2.0_react@18.2.0_sass@1.69.5/node_modules/next/dist/build/webpack/loaders/next-flight-loader/action-client-wrapper.js
./src/pages/tests/email-scenario-guide.jsx
Answered by Griffon Nivernais
Rewriting to app router (despite it being very painstaking) resolved the error, very tedious.
View full answer

7 Replies

Griffon NivernaisOP
Here's the code.
"use server";

import ReactPDF from "@react-pdf/renderer";

import graph from "@/server/graph";
import ScenarioGuide from "@/server/pdfs/ScenarioGuide";

// https://stackoverflow.com/a/63361543
async function streamToBase64(stream) {
    const chunks = [];

    for await (const chunk of stream) {
        chunks.push(Buffer.from(chunk));
    }

    return Buffer.concat(chunks).toString("base64");
}

export default async function createQuiz(req, res) {
    const recruiterEmail = "*";

    await graph.sendEmail(recruiterEmail, {
        attachments: [
            await graph.createAttachment("Scenario Guide.pdf", {
                skipAutoFetchFile: true,
                isInline: false,
                contentBytes: await streamToBase64(
                    await ReactPDF.renderToStream(
                        <ScenarioGuide
                            quizCreationDate={new Date()}
                            recruiterName="Name"
                            recruiterEmail={recruiterEmail}
                            scenarioNames={["Derek", "Margaret", "Mr Singh"]}
                        />,
                    ),
                ),
                contentId: undefined,
                contentType: "application/pdf",
            }),
        ],
        subject: "Subject",
        content: "Check attachments.",
    });

    res.status(200).end();
}
Before I didn't have the "use server" directive, and it spat out a Webpack error saying "fs" couldn't be found for some reason.
Griffon NivernaisOP
And here's my Next config:
import path from "path";
import process from "process";

import NextBundleAnalyzer from "@next/bundle-analyzer";

import config from "./src/server/config.js";

const withBundleAnalyzer = NextBundleAnalyzer({
    enabled: config.ANALYZE ?? false,
});

/**
 * @type {import('next').NextConfig}
 **/
export default withBundleAnalyzer({
    // NGinx is configured to automatically compress contents to GZip
    compress: false,
    reactStrictMode: true,
    // TODO: Revert this when you're done converting to TS
    typescript: {
        ignoreBuildErrors: true,
    },

    // TODO: Revert this when you're done converting to TS
    webpack(config) {
        return {
            ...config,
            experiments: {
                ...config.experiments,
                topLevelAwait: true,
            },
            resolve: {
                ...config.resolve,
                alias: {
                    ...config.resolve.alias,
                    "@": path.resolve("./src"),
                },
            },
        };
    },
});
Sorry there's so much to digest, I literally can't figure out what the issue is and the errors make no sense. I've added packages, removed packages, changed runtimes and nothing.
Griffon NivernaisOP
Bump.
Got some sleep and am wondering if the issue is me using Puppeteer + Handlebars to generate emails, so might have to rewrite them using React Email.
Griffon NivernaisOP
Rewriting to app router (despite it being very painstaking) resolved the error, very tedious.
Answer