When using a pdfjs worker, I get this issue on older browsers. I am suspecting that the new feature # for private class is not being polyfilled. I have however no idea how to solve this. I would expect hope it to be some kind of configuration in Vite that is currently missing.
Error in XCode for Safari 14 or lower:
⚡️ SyntaxError: Invalid character: '#'
⚡️ URL: capacitor://localhost/assets/pdf.worker.min-339a4ae5.js
I use the worker like this:
import pdfWorker from 'pdfjs-dist/build/pdf.worker.min.js?url';
PdfJs.GlobalWorkerOptions.workerSrc = pdfWorker;
And vite config looks like this
export default defineConfig({
plugins: [
react(),
legacy({
targets: ['Safari >= 14', 'iOS >= 14', 'not IE 11', 'Android >= 10'],
polyfills: true,
}),
svgrPlugin(),
checker({ typescript: true }),
],
resolve: {
alias: tsconfigPathAliases,
},
server: {
open: true,
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/setupTests.ts',
},
} as UserConfigExport);