Closed Mythie closed 1 year ago
What's the bundling issue this PR trying to solve?
base/shared/util.js
is not an ES Module, can not be safely imported. It's part of lib
and extends native node's utils.
Besides, PR has errors when running 'npm run test':
'''
node:internal/process/esm_loader:97
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: ... '''
using in nextjs v13 occurs this error:
error - Error [ReferenceError]: nodeUtil is not defined
at eval (eval at <anonymous> (webpack-internal:///(sc_server)/./node_modules/pdf2json/lib/pdf.js), <anonymous>:1235:1)
at eval (webpack-internal:///(sc_server)/./node_modules/pdf2json/lib/pdf.js:79:1)
So looking more into this it has to do with Next13 route handlers and their bundling being aimed more at edge functions.
Not an error with the library fortunately, I’ll close this out.
@Mythie were you able to fix this elsewhere?
@Mythie were you able to fix this elsewhere?
Hey, once I swapped from route handlers to normal API routes in Next.js everything worked. Main issue was things getting bundled for edge rather than node.
@Mythie Thank you, trying the same! Why is edge runtime important here vs. node?
@Mythie Thank you, trying the same! Why is edge runtime important here vs. node?
Because it's running on the edge it doesn't have access to traditional Node API's and thus can't bundle something like pdf2json
. I'd suggest tossing whatever interacts with this package in an api/
route until Next.js sort out route handlers and bundling them for the Node runtime.
Update the nodeUtil imports to point to the
base/shared/util.js
file instead of the node.js native util package.Resolves some bundling issues with next.js.