-
-
Notifications
You must be signed in to change notification settings - Fork 127
fix: handle CommonJS export for trim-canvas to prevent runtime TypeError #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the description, which includes things like emojis, improper list formatting (I edited it later to fix it), lacking explanations or citations for many arbitrary and unnecessary changes, this has many hallmarks that it was generated by an LLM. And based on many of the unnecessary, redundant, and CI-breaking changes -- see the in-line comments -- it seems like it was not verified by a human either...
Please do not spam maintainers with unverified, AI-generated changes that do not even follow the codebase style or package manager.
This resolves
TypeError: trimCanvas is not a function
Furthermore, while this lacks any sort of citations or proper explanations, this seems like this is supposed to be a fix for #128. This does not address my comments there nor the issues I have filed with build tools, as that bug is within those downstream build tools that users use, and not here in this repo.
You also have not provided a reproduction as evidence that this fixes that issue and this does not pass CI.
| "@types/signature_pad": "^2.3.0", | ||
| "signature_pad": "^2.3.2", | ||
| "trim-canvas": "^0.1.0" | ||
| "trim-canvas": "^0.1.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not make arbitrary changes to versions. This is not necessary.
| "@rollup/plugin-commonjs": "^21.1.0", | ||
| "@rollup/plugin-node-resolve": "^13.2.1", | ||
| "@testing-library/react": "^16.1.0", | ||
| "@types/babel__core": "^7.20.5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not arbitrarily add libraries with arbitrary and conflicting versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not arbitrarily add entire package managers and their lockfiles. Use the existing ones
| const canvas = this.getCanvas(); | ||
| const copy = document.createElement("canvas"); | ||
| copy.width = canvas.width; | ||
| copy.height = canvas.height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not arbitrarily make stylistic changes to any part of the code, let alone one specific part while leaving the rest in a different style
| "outDir": "dist", | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "skipLibCheck": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not make arbitrary configuration changes. Many of these are also already configured as such, so you have largely duplicated config unnecessarily. The other changes, which similarly have no explanations for them, are conflicting and not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not create arbitrary files and folders, particularly not unnecessary files, conflicting types, and duplicative folders.
| // Handle both CJS and ESM default export forms | ||
| const trimFn = (trimCanvasImport as any).default || trimCanvasImport; | ||
|
|
||
| return typeof trimFn === "function" ? trimFn(copy) : copy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function should not no-op if there is a problem, especially with no logging to the user that something went wrong. Such behavior would be very misleading to users as it clearly breaks the API contract
| return trimCanvas(copy) | ||
| } | ||
| // Handle both CJS and ESM default export forms | ||
| const trimFn = (trimCanvasImport as any).default || trimCanvasImport; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per vercel/next.js#78267, this should be automatically done by the bundler; TypeScript's esModuleInterop does this and several other steps.
Adding that into this codebase means ensuring it compiles correctly and is compatible with other bundlers, which is normally the responsibility of the bundlers themselves. Shifting the responsibility like that makes me reticent to include it, especially if it doesn't come with lots of compatibility verifications
Fixed a TypeError caused by incorrect default import from 'trim-canvas'.
✅ Changes:
import trimCanvas from "trim-canvas"withimport * as trimCanvas from "trim-canvas"and handled export properly for production build.
This resolves
TypeError: trimCanvas is not a functionduring build/runtime.