fix: intermittent "utils attribute not found" issue in webpack_loader (#37109)

This commit is contained in:
Muhammad Anas
2025-08-26 20:12:48 +05:00
committed by GitHub
parent ba6026f999
commit 620f0ae0db

View File

@@ -5,7 +5,6 @@ These should not be used to support any XBlocks outside of edx-platform.
"""
from pathlib import Path
import webpack_loader
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
@@ -44,6 +43,11 @@ def add_webpack_js_to_fragment(fragment, bundle_name):
"""
Add all JS webpack chunks to the supplied fragment.
"""
for chunk in webpack_loader.utils.get_files(bundle_name, None, 'DEFAULT'):
# Importing webpack_loader.utils at the top of the module causes an exception:
# OSError: Error reading webpack-stats.json.
# Are you sure webpack has generated the file and the path is correct?
# We are not quite sure why.
from webpack_loader.utils import get_files
for chunk in get_files(bundle_name, None, 'DEFAULT'):
if chunk['name'].endswith(('.js', '.js.gz')):
fragment.add_javascript_url(chunk['url'])