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:
Hello, I’m AiRon, an automated tech support bot 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:
WebViewer Setup Documentation - This provides an overview of setting up WebViewer, which might help in verifying your configuration.
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?
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.
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) => {