diff --git a/xmodule/util/builtin_assets.py b/xmodule/util/builtin_assets.py index cb1fca721414..6b8eb86ecf34 100644 --- a/xmodule/util/builtin_assets.py +++ b/xmodule/util/builtin_assets.py @@ -5,7 +5,6 @@ """ 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'])