Uncaught DOMException: Failed to execute ‘importScripts’ on ‘WorkerGlobalScope’
28 Sep 20231 minute to read
Another error that can occur when setting up the ej2-pdfviewer-library
without the necessary assets is the Uncaught DOMException: Failed to execute ‘importScripts’ on ‘WorkerGlobalScope’. This error typically arises when a web worker attempts to load a script (e.g., pdfium.js
or pdfium.wasm
) and fails to do so.
To troubleshoot and resolve this error, consider the following steps:
-
Check Asset Availability: Ensure that the required assets, specifically
pdfium.js
andpdfium.wasm
, are present in the correct locations within your project. Confirm that they are accessible and have been copied correctly. -
Network and CORS: Verify that there are no network-related issues preventing the web worker from fetching the assets. Also, address any CORS-related problems, especially if the assets are hosted on a different origin.
NOTE
If ej2-pdfviewer-lib folder is not available in the ‘src/assets’, copy the contents of the ej2-pdfviewer-lib folder from ./node_modules/@syncfusion/ej2-pdfviewer/dist to the src/assets directory using the command:
cp -R ./node_modules/@syncfusion/ej2-pdfviewer/dist/ej2-pdfviewer-lib src/assets/ej2-pdfviewer-lib