From 983cf99af08dc6e9a37de65bd84b23b385358a5a Mon Sep 17 00:00:00 2001 From: reidemeister Date: Thu, 11 Jun 2026 15:34:19 +0200 Subject: [PATCH 1/2] fix: patch license-webpack-plugin to unblock the labextension build `make run` falls back to a local Docker build on platforms with no prebuilt image (e.g. Apple Silicon / linux/arm64). That build failed in the `labext-builder` stage at `jlpm run build:prod`: TypeError: Cannot read properties of undefined (reading 'trim') at WebpackInnerModuleIterator.getActualFilename (license-webpack-plugin/dist/WebpackInnerModuleIterator.js:61) @jupyterlab/builder adds JSONLicenseWebpackPlugin only in production mode, so the dev build was unaffected. license-webpack-plugin@4.0.2 (latest, unchanged since 2022) assumes Module Federation "provide module" entries look like `provide module ... = `. Modern webpack (5.107) emits the extension's self-provided share with a pipe separator and no `=`: provide module (default) torchcode-labext@0.1.0|/app/lib/index.js so `filename.split('=')[1]` is undefined and `.trim()` throws. The extension pins `webpack@^5.76` with no committed lockfile, so a fresh `jlpm install` now resolves a webpack that triggers this. Fix: a yarn `resolutions` patch makes getActualFilename return null for self-provided shares with no `=` (the extension's own code, already excluded from the license report) instead of crashing. - labextension/package.json: resolutions -> patched license-webpack-plugin - labextension/.yarn/patches/...: the one-line guard - Dockerfile: COPY labextension/.yarn before `jlpm install` so the patch is present when dependencies are resolved --- Dockerfile | 3 +++ ...se-webpack-plugin-npm-4.0.2-1e0a964980.patch | 17 +++++++++++++++++ labextension/package.json | 3 +++ 3 files changed, 23 insertions(+) create mode 100644 labextension/.yarn/patches/license-webpack-plugin-npm-4.0.2-1e0a964980.patch diff --git a/Dockerfile b/Dockerfile index 53d7835..ddbb7c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,6 +33,9 @@ FROM build-base AS labext-builder # Copy manifests first so dependency install is cacheable between source edits. WORKDIR /src/labextension COPY labextension/.yarnrc.yml labextension/package.json labextension/pyproject.toml labextension/tsconfig.json labextension/install.json ./ +# Yarn resolutions reference a local patch (license-webpack-plugin fix); it must +# exist before `jlpm install` resolves dependencies. +COPY labextension/.yarn ./.yarn RUN jlpm install COPY labextension/style ./style diff --git a/labextension/.yarn/patches/license-webpack-plugin-npm-4.0.2-1e0a964980.patch b/labextension/.yarn/patches/license-webpack-plugin-npm-4.0.2-1e0a964980.patch new file mode 100644 index 0000000..162460f --- /dev/null +++ b/labextension/.yarn/patches/license-webpack-plugin-npm-4.0.2-1e0a964980.patch @@ -0,0 +1,17 @@ +diff --git a/dist/WebpackInnerModuleIterator.js b/dist/WebpackInnerModuleIterator.js +index 282271e7411aa6221e408befb4ecfb259edc5896..b55935ad110758a1be09c614fbc1fdc4ed97133e 100644 +--- a/dist/WebpackInnerModuleIterator.js ++++ b/dist/WebpackInnerModuleIterator.js +@@ -58,7 +58,11 @@ var WebpackInnerModuleIterator = /** @class */ (function () { + return tokens[tokens.length - 1]; + } + if (filename.indexOf('provide module') === 0) { +- return filename.split('=')[1].trim(); ++ // Newer webpack emits self-provided Module Federation shares as ++ // "provide module (default) name@version|/path" (pipe separator, no '='), ++ // so split('=')[1] is undefined. Skip those instead of crashing on .trim(). ++ var providedFile = filename.split('=')[1]; ++ return providedFile == null ? null : providedFile.trim(); + } + if (filename.indexOf('consume-shared-module') === 0) { + var tokens = filename.split('|'); diff --git a/labextension/package.json b/labextension/package.json index ab01ab3..1b1fa1e 100644 --- a/labextension/package.json +++ b/labextension/package.json @@ -36,5 +36,8 @@ "jupyterlab": { "extension": true, "outputDir": "torchcode_labext/labextension" + }, + "resolutions": { + "license-webpack-plugin@^4.0.2": "patch:license-webpack-plugin@npm%3A4.0.2#./.yarn/patches/license-webpack-plugin-npm-4.0.2-1e0a964980.patch" } } From 8b34ee50fbefe188119cf6ad8c8ee385618eecdf Mon Sep 17 00:00:00 2001 From: reidemeister Date: Thu, 11 Jun 2026 15:47:16 +0200 Subject: [PATCH 2/2] fix: install numpy in the runtime image to silence torch NumPy warning torch >=2 treats NumPy as an optional dependency, so `pip install torch` (from the CPU index) does not pull it in. As a result `import torch` in the container prints: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at .../tensor_numpy.cpp:84) and all tensor<->numpy interop (e.g. `tensor.numpy()`, `from_numpy`) is disabled. Add numpy to the runtime image so the first notebook cell is clean and interop works. Verified: torch 2.12.0+cpu + numpy 2.4.6, `import torch` no longer warns. --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index ddbb7c8..b87e023 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,10 +55,13 @@ WORKDIR /app COPY --from=judge-builder /tmp/wheels /tmp/wheels COPY --from=labext-builder /tmp/wheels /tmp/wheels +# torch >=2 treats NumPy as optional; without it `import torch` prints a +# "Failed to initialize NumPy" warning and tensor<->numpy interop is disabled. RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir \ torch --index-url https://download.pytorch.org/whl/cpu && \ pip install --no-cache-dir \ + numpy \ /tmp/wheels/*.whl && \ rm -rf /tmp/wheels