You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Get a runtime error: TypeError: trim_canvas__WEBPACK_IMPORTED_MODULE_8__ is not a function
Current vs. Expected behavior
I expect the "Trim" button to work and show a trimmed version of the signature underneath the buttons instead of getting a run-time error.
The bundler configuration appears to have some bug in its ESM-CJS interop. The react-signature-canvas package defaults to an ESM build and imports trim-canvas, which only has a CJS/UMD build. It only has a single default export which is compiled as exports=trimCanvas(...).
Next.js's bundled code seems to be missing the __importDefault helper of TypeScript's esModuleInterop and assuming that trim-canvas's exports is an object, when it is actually a singular function.
This differs from using Webpack directly or Parcel, which both work fine without errors. Given the difference to plain Webpack, this suggests that there is a bug in Next.js's Webpack configuration.
As further evidence, using the CJS/UMD build of react-signature-canvas works fine with:
The Vite reproduction has a similar error to Next.js, but only with vite dev and not with vite build && vite preview.
Other Related Issues
These aren't entirely the same, but if you search the issues for "is not a function" or "webpack_imported_module", you'll get many results. Specifically these seemed quite similar: #65056, #63795, #57584 and possibly many more like #62953, #68413, #52188 etc. __WEBPACK_IMPORTED_MODULE_*__ is not a function is a common error in these and the ESM-CJS interop is referenced in some too.
Again, they're not exactly the same though and don't all have minimal reproductions. This one is a very tiny reproduction, ~30 LoC of Next.js code and the imported libraries are ~100 LoC each. I have also maintained both the directly imported library (react-signature-canvas) and its dependency (trim-canvas) for almost a decade now, so I know them inside-out. I'm raising this because my users filed issues like agilgur5/react-signature-canvas#128 about this and I debugged it as a Next.js issue.
The text was updated successfully, but these errors were encountered:
Link to the code that reproduces this issue
https://github.com/agilgur5/rsc-issue-128. See a live demo on StackBlitz
To Reproduce
npm install && npm run dev
TypeError: trim_canvas__WEBPACK_IMPORTED_MODULE_8__ is not a function
Current vs. Expected behavior
I expect the "Trim" button to work and show a trimmed version of the signature underneath the buttons instead of getting a run-time error.
The bundler configuration appears to have some bug in its ESM-CJS interop. The
react-signature-canvas
package defaults to an ESM build and importstrim-canvas
, which only has a CJS/UMD build. It only has a single default export which is compiled asexports=trimCanvas(...)
.Next.js's bundled code seems to be missing the
__importDefault
helper of TypeScript'sesModuleInterop
and assuming thattrim-canvas
'sexports
is an object, when it is actually a singular function.This differs from using Webpack directly or Parcel, which both work fine without errors. Given the difference to plain Webpack, this suggests that there is a bug in Next.js's Webpack configuration.
As further evidence, using the CJS/UMD build of
react-signature-canvas
works fine with:Using an older version like
1.0.7
that only has a UMD build similarly works fine.Only the ESM-CJS interop of dependencies of dependencies seems to have an issue.
Provide environment information
Which area(s) are affected? (Select all that apply)
Webpack, SWC
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local)
Additional context
Other Troubleshooting
Still has the same error when:
canary
swcMinify: false
innext.config.js
esModuleInterop
intsconfig.json
Other Bundlers
vite dev
and not withvite build && vite preview
.Other Related Issues
These aren't entirely the same, but if you search the issues for "is not a function" or "webpack_imported_module", you'll get many results. Specifically these seemed quite similar: #65056, #63795, #57584 and possibly many more like #62953, #68413, #52188 etc.
__WEBPACK_IMPORTED_MODULE_*__ is not a function
is a common error in these and the ESM-CJS interop is referenced in some too.Again, they're not exactly the same though and don't all have minimal reproductions. This one is a very tiny reproduction, ~30 LoC of Next.js code and the imported libraries are ~100 LoC each. I have also maintained both the directly imported library (
react-signature-canvas
) and its dependency (trim-canvas
) for almost a decade now, so I know them inside-out. I'm raising this because my users filed issues like agilgur5/react-signature-canvas#128 about this and I debugged it as a Next.js issue.The text was updated successfully, but these errors were encountered: