@pdftron/webviewer no longer works in vite-rolldown version 7.19.0

Starting from version 7.19.0, vite-rolldown changed the way default exports are resolved to make it more consistent with other bundlers, such as esbuild and webpack.

This change breaks @pdftron/webviewer. We now see the following error in the console:

Uncaught TypeError: WebViewer is not a function

Looking at https://cdn.jsdelivr.net/npm/@pdftron/webviewer@11.8.0/public/core/webviewer-core.min.js, both exports.default and __esModule are used, which may violate this rule: Rules | publint.

Additional references:

WebViewer version:
11.8.0

Reproduction example:

1 Like

Hello, I’m AiRon, an automated tech support bot :robot:
While you wait for one of our customer support representatives, I can help you with your question.


The issue you’re facing is related to the changes in how default exports are handled in the latest version of vite-rolldown. This can lead to compatibility issues with the way @pdftron/webviewer exports its modules. The error you’re seeing, “Uncaught TypeError: WebViewer is not a function”, typically indicates that the module is not being imported correctly due to these export changes.

Some things you can try:

  • Ensure you’re using the correct import syntax for the module. If the default export isn’t working, try importing the module in a named fashion.

  • Check if there’s an updated version of @pdftron/webviewer that resolves this compatibility issue.

  • Consider using a different bundler or reverting to an earlier version of vite-rolldown where this issue doesn’t occur.

  • Review the vite-rolldown configuration to see if there are any options available to handle default exports differently.



Here are some resources that might help you:


Hopefully, this helps you solve your problem while you wait for a human to get back to you.

1 Like

Hello Haithem,

Thank you for contacting WebViewer Forums.

I looked into updating the vite version of one of our sample projects to v7.1 which uses vite rather than the vite-rolldown package and it seems to compile correctly. Is there a reason to use the vite-rollback package?

Please see our sample projects here for reference: webviewer-samples/webviewer-react at main · ApryseSDK/webviewer-samples · GitHub

Regards,
Luke

1 Like

Hey Luke,

The next version, Vite 8, is going to be based on Rolldown, which improves build performance and comes with other new built-in features. You can read more about it here: Rolldown Integration | Vite.

Fixing this issue now will let people upgrade to Vite version 8 seamlessly once it gets released.

Thank you!

1 Like

Hello Haithem,

Thank you for your reply.

I was able to workaround the issue by adding .default explicitly to WebViewer to access the default export with Vite 7 in your project. Please let me know if this works for you:

import * as WebViewer from '@pdftron/webviewer' // optional import change
WebViewer.default(
      {
        path: 'lib/webviewer',
        ...
      },
      viewer.current
    ).then((instance) => {

Regards,
Luke

1 Like