Skip to content

NextJS + vite dev run-time error: Uncaught TypeError: trim_canvas.default is not a function #128

Open
@andrefpoliveira

Description

@andrefpoliveira

maintainer edit: This issue has gotten a little popular, please see a summary of the root cause and workarounds in the below linked comments:


Hey! I'm probably doing something wrong but I can't figure out what...

I have a Next JS app and I have the following object:

"use client";
import { useRef } from "react";
import SignatureCanvas from "react-signature-canvas";

export default function SignaturePad({ onSave }) {
    const sigCanvas = useRef(null);

    const clear = (event) => {
        event.preventDefault();
        sigCanvas.current.clear();
        onSave(null);
    };

    const strokeFinished = (event) => {
        event.preventDefault();
        const dataURL = sigCanvas.current.getTrimmedCanvas().toDataURL("image/png");
        onSave && onSave(dataURL); // Send to parent component
    };

    return (
        <fieldset className="fieldset w-full">
            <legend className="fieldset-legend">Assinatura</legend>
            <div className="border-1 rounded-md input w-full h-[150px] cursor-crosshair">
                <SignatureCanvas
                    ref={sigCanvas}
                    penColor="black"
                    onEnd={strokeFinished}
                    canvasProps={{ className: "w-full h-[150px] rounded-md"}}
                />
            </div>
            <div className="flex space-x-2">
                <button onClick={clear} className="btn btn-primary w-full mt-2">
                    Limpar
                </button>
            </div>
        </fieldset>
    );
}

However, I'm getting this error:

Uncaught TypeError: p is not a function
  at e.getTrimmedCanvas (145-1f8f2f744481203b.js:1:12839)
  at f.onEnd (page—-dda8c99f385158aa.js:1:2153)
  at f._strokeEnd (145-1f8f2f744481203b.js:1:6137)
  at HTMLCanvasElement._handleTouchEnd (145-1f8f2f744481203b.js:1:3327)
Image

Does anyone know how to fix this? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: supportAsking for support with something or a specific use caseproblem: staleIssue author has not respondedscope: downstreamIssue in a downstream library, not in this library itselfsolution: out-of-scopeThis is out of scope for this projectsolution: workaround availableA workaround is available for this issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions