Skip to content

Server-only module referenced by client #10506

Open
@psm-solution-group

Description

@psm-solution-group

Reproduction

/

System Info

latest remix & vite version

Used Package Manager

npm

Expected Behavior

get error:

[commonjs--resolver] Server-only module referenced by client
    '~/data/pdf.server' imported by route 'app/routes/pdf_verify_return.tsx'
  Remix automatically removes server-code from these exports:
    `loader`, `action`, `headers`

Actual Behavior

here is the code:

import { IPDF_BOOKING_VERIFY, PDF_BUCHUNGS } from "~/data/pdf.server";

export const getPDFVerify = async ({db_name, id, p }: { db_name: DB_NAME_TYPE; id: number; p: IProcessID_DATA; }) => {
  // render the PDF as a stream so you do it async
  let stream = await renderToStream(<PDF_BUCHUNGS {...d} />);

  // and transform it to a Buffer to send in the Response
  let body: Buffer = await new Promise((resolve, reject) => {
    let buffers: Uint8Array[] = [];
    stream.on("data", (data) => {
      buffers.push(data);
    });
    stream.on("end", () => {
      resolve(Buffer.concat(buffers));
    });
    stream.on("error", reject);
  });


  // finally create the Response with the correct Content-Type header for
  // a PDF
  return body;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions