can not use the 'qr-image' package in pages function

this is the code in my ./functions folder, i just copy this code from workers example.(has fix the ‘onRequest’ to be Compatible with pages function )

import qr from 'qr-image';

export async function onRequest(context) {
  if (context.request.method === "POST") {
    return generateQRCode(context.request);
  }

  return new Response(landing, {
    headers: {
      "Content-Type": "text/html",
    },
  });
}

async function generateQRCode(request) {
  const { text } = await request.json();
  const headers = { "Content-Type": "image/png" };
  const qr_png = qr.imageSync(text || "https://workers.dev");

  return new Response(qr_png, { headers });
}

const landing = `xxxx`;


the build log

10:53:56.152    Success: Finished cloning repository files
10:53:56.935    No build command specified. Skipping build step.
10:53:56.936    Found Functions directory at /functions. Uploading.
10:53:58.488    ✘ [ERROR] 1 error(s) and 0 warning(s) when compiling Worker.
10:53:58.489    
10:53:58.489    
10:53:58.492    
10:53:58.495    ✘ [ERROR] Could not resolve "qr-image"
10:53:58.498    
10:53:58.499        api/qr.js:1:15:
10:53:58.499          1 │ import qr from 'qr-image';
10:53:58.499            ╵                ~~~~~~~~~~
10:53:58.499    
10:53:58.499      You can mark the path "qr-image" as external to exclude it from the bundle, which will remove this error.
10:53:58.501    
10:53:58.501    
10:53:58.501    ✘ [ERROR] Build failed with 1 error:
10:53:58.501    
10:53:58.502      api/qr.js:1:15: ERROR: Could not resolve "qr-image"
10:53:58.502    
10:53:58.502    
10:53:58.513    Failed building Pages Functions.
10:53:59.442    Failed: an internal error occurred. If this continues, contact support: https://cfl.re/3WgEyrH
image.png
Was this page helpful?