This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/web/troubleshooting/chunkloaderror-during-pspdfkit-to-nutrient-migration-in-ember.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Fix ChunkLoadError in Ember | Nutrient

Migrating from PSPDFKit to Nutrient Web SDK can introduce unexpected challenges, particularly in complex build environments like Ember.js applications. One of the most common issues developers encounter is a ChunkLoadError during automated testing, which can make a test suite flaky.

If chunk loading fails after you migrate to Nutrient Web SDK, this guide explains the root causes and shows how to resolve the failures.

Understanding the ChunkLoadError

The ChunkLoadError typically manifests as the following:

ChunkLoadError: Loading chunk 42 failed.
(error: http://localhost:36173/assets/nutrient-viewer-lib/chunk-standalone-server-076587c32d94e70b.js)

This error occurs when Nutrient Web SDK can’t locate its required chunk files during initialization. While it might seem like a network issue, it’s usually related to how your application serves static assets.

To confirm where initialization stops, refer to the debug logging guide and check the last visible stage in the browser console.

Root cause: Missing asset integration

Nutrient Web SDK uses dynamic imports to load chunks on demand, which improves performance by loading only what’s needed. In the following case, the issue stemmed from how the build process handled the SDK assets:

"copy-nutrient-files": "cp -R ./node_modules/@nutrient-sdk/viewer/dist/ ./public/assets/"

The common migration mistake

A typical migration approach might include:

  1. Updating package dependencies from pspdfkit to @nutrient-sdk/viewer.
  2. Copying SDK assets using a build script, such as cp -R ./node_modules/@nutrient-sdk/viewer/dist/ ./public/assets/.
  3. Updating initialization code to use Nutrient APIs.

While this approach works in development, it could fail in other environments, especially when running parallel tests. Copying assets with a script doesn’t properly integrate them into your build system’s asset pipeline.

Two approaches to resolve ChunkLoadError

You can resolve ChunkLoadError issues during migration with two primary approaches.

The most effective approach is to integrate the Nutrient assets directly into your Ember build process using Broccoli’s Funnel plugin(opens in a new tab). This ensures assets are always available and properly served.

If your app doesn’t list them yet, add both plugins as dev dependencies:

Terminal window
npm install --save-dev broccoli-funnel broccoli-merge-trees

broccoli-funnel 4 requires Node.js 20.19 or later on the 20.x line, or 22.12 or later. On an older version, install broccoli-funnel@3 instead.

Update your ember-cli-build.js file to match the following:

const EmberApp = require("ember-cli/lib/broccoli/ember-app");
const broccoliFunnel = require("broccoli-funnel");
const Funnel = broccoliFunnel.Funnel || broccoliFunnel;
const mergeTrees = require("broccoli-merge-trees");
module.exports = function (defaults) {
const app = new EmberApp(defaults, {
// Your existing configuration.
});
// Add Nutrient assets to build tree.
const nutrientAssets = new Funnel(
"vendor/nutrient-viewer-lib",
{
srcDir: "/",
destDir: "/assets/nutrient-viewer-lib",
},
);
// Include Nutrient assets in the build output.
return mergeTrees([app.toTree(), nutrientAssets]);
};

The funnel source is the nutrient-viewer-lib/ folder from the assets archive. Download the archive for the same version as @nutrient-sdk/viewer and extract it into vendor/ (create it if it doesn’t exist). If you use another folder, change the funnel’s source path to match. Download it again whenever you update the package. Don’t point the funnel at node_modules/@nutrient-sdk/viewer/dist/nutrient-viewer-lib. Starting with Nutrient Web SDK 1.9.1, assets from the npm package show the Copying assets from the npm package is deprecated warning in the console.

Solution 2: Parallel execution adjustments

As an alternative or complementary approach, you can reduce the parallel execution load and add detailed CI logging to minimize race conditions:

  1. Reduce parallelism — Change from --parallel=6 to --parallel=3 in your test command.
  2. Add detailed CI logging — Monitor asset loading behavior.
  3. Implement retry logic — Add it to your preloadWorker function.
// Update your exam script.
"exam": "ember exam --parallel=3 --load-balance --test-port=0 --random"

Why solution 1 works best

The funnel approach (solution 1) succeeds where copy scripts fail because of:

  1. Build-time integration — The build tree includes the assets, ensuring they’re always available when your application loads.
  2. Consistent asset serving — Ember’s asset pipeline serves the assets with proper caching headers.
  3. Parallel test support — Multiple test processes can access assets simultaneously without race conditions.
  4. Environment consistency — The same asset handling works across development, testing, and production environments.

Complete setup guide

Before you start the detailed setup, make sure your project references Nutrient’s assets correctly throughout the application.

Configure your baseUrl

Ensure your SDK initialization uses the correct baseUrl:

const config = {
baseUrl: location.protocol + "//" + location.host + "/assets/",
// ... other configuration options.
};

Remove copy scripts

Once you’ve implemented solution 1, you can remove any manual copy scripts from your package.json file:

{
"scripts": {
// Remove this line.
// "copy-nutrient-files": "cp -R ./node_modules/@nutrient-sdk/viewer/dist/ ./public/assets/",
// Keep your exam command as is (or reduce parallelism if needed).
"exam": "ember exam --parallel=6 --load-balance --test-port=0 --random"
}
}

Additional considerations

Once the main setup is complete, these additional considerations help your assets and tests behave reliably in all environments.

Fingerprinting

If you’re using asset fingerprinting in production, exclude the Nutrient assets from fingerprinting to maintain consistent URLs:

fingerprint: {
enabled: isProductionLike,
exclude: [
'/nutrient-viewer-lib/**/*'
],
}

Error handling in tests

To make tests more resilient, consider adding retry logic to your preloadWorker function:

async preloadWorker() {
if (this.hasPreloaded) return;
const maxRetries = 3;
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
this.set('hasPreloaded', true);
return await PSPDFKit.preloadWorker(this.config);
} catch (error) {
if (attempt === maxRetries) throw error;
console.warn(`Preload attempt ${attempt} failed, retrying...`);
await delay(1000 * attempt);
}
}
}

Verification

After implementing these changes, verify the fix by:

  1. Running your full test suite with parallel execution using ember exam --parallel=6.
  2. Checking that chunk files load consistently across all test runs.
  3. Confirming the solution works in both local and CI environments.

Key takeaways

When migrating from PSPDFKit to Nutrient Web SDK:

  • Don’t rely on copy scripts for asset management in production applications
  • Integrate assets into your build process using proper build tools like Broccoli Funnel
  • Test thoroughly in parallel execution environments that mirror your CI setup
  • Configure asset serving correctly to handle concurrent requests

ChunkLoadError is an asset serving issue, not a networking problem. Integrating Nutrient’s assets into your build pipeline ensures reliable SDK initialization across all environments.

This approach fixes the immediate ChunkLoadError. It also gives your Nutrient integration a more reliable foundation and prevents similar issues as you scale your application.