Polyfill for doesn't seem to work correctly for imported worker in Vite

196 Views Asked by At

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);
0

There are 0 best solutions below