NPM Libraries that use unsuppoted syntax

I’m working with an NPM package that uses optional chaining. It sounds like I need to configure webpack to be able to understand this syntax. I don’t see any information in the documentation on how to do this.

The package for reference is pdfjs-dist.
https://www.npmjs.com/package/pdfjs-dist

Error message for reference:

"stdout": "./node_modules/pdfjs-dist/build/pdf.mjs 402:14\nModule parse failed: Unexpected token (402:14)\nYou may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders\n| }\n| function _isValidProtocol(url) {\n> switch (url?.protocol) {\n| case \"http:\":\n| case \"https:\":\n @ ./src/index.ts 12:17-38",

Hi,

We work cover in depth managing npm dependencies here
https://www.palantir.com/docs/foundry/functions/add-dependencies/

Unfortunately newer versions of pdfjs-dist are known to have issues in our environment due to unsupported dependencies. Yet 2.6.347 of pdfjs-dist and lower are used and confirmed to work for typescript function authors.

Hope this helps!

Thanks for the reply here. Do you know what setting folks used for the global worker? I can’t seem to get it right in my environment.

A code snippet on the import and setting the global worker would be much appreciated. Thanks!