-
Notifications
You must be signed in to change notification settings - Fork 357
fix: make local Docker build & run work end-to-end (labextension build + numpy)#23
Open
reidemeister94 wants to merge 2 commits into
Open
Conversation
`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 ... = <path>`. 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
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.
@reidemeister94
reidemeister94
changed the title
(削除) fix: unblock local/CI build by patching license-webpack-plugin crash (削除ここまで)
(追記) fix: make local Docker build & run work end-to-end (labextension build + numpy) (追記ここまで)
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
Summary
On platforms without a prebuilt image (e.g. Apple Silicon /
linux/arm64),make runfalls back to a local Docker build (added in #13). On a fresh build that path was broken in two independent ways. This PR contains both fixes somake runworks end-to-end: the image builds, andimport torchin the first notebook cell is clean.Fix 1 — labextension build crash (
build:prod)Problem
The local build aborts in the
labext-builderstage atjlpm run build:prod:The dev build is unaffected — the crash only happens in production mode.
Root cause
@jupyterlab/builderaddsJSONLicenseWebpackPluginonly inmode === 'production', which is whybuild:prodbreaks butbuild:devdoes not.That plugin uses
license-webpack-plugin@4.0.2(latest, unchanged since 2022). ItsgetActualFilename()assumes Module Federation "provide module" entries look likeprovide module ... = <path>and doesfilename.split('=')[1].trim().Modern webpack (5.107, what
jlpm installresolves today) emits the extension's self-provided share with a pipe separator and no=:so
split('=')[1]isundefinedand.trim()throws.The extension pins
webpack@^5.76(transitively) with no committed lockfile (labextension/yarn.lockis git-ignored), so a freshjlpm installresolves a newer webpack that triggers this. The published:latestimage predates that webpack bump, which is why it still works while a fresh build doesn't.Fix
A minimal, declarative patch via Yarn
resolutions+ thepatch:protocol (no lockfile needed; applied whereverjlpm installruns):Returning
nullfor a self-provided share is correct — it is the extension's own code, already excluded from the license report (excludedPackageTest). Behaviour is unchanged when an=is present.labextension/.yarn/patches/license-webpack-plugin-npm-4.0.2-*.patch— the one-line guardlabextension/package.json—resolutionsentry applying the patchDockerfile—COPY labextension/.yarnbeforejlpm installso the patch exists at resolve timeFix 2 — missing NumPy at runtime
Problem
With the build fixed, the container starts but
import torchin the first notebook cell prints:and tensor↔numpy interop (
tensor.numpy(),from_numpy, ...) is disabled.Root cause
torch >=2treats NumPy as an optional dependency, sopip install torch(from the CPU index) does not pull it in, and nothing else in the image installs it.Fix
Install
numpyin the runtime stage (Dockerfile).torch-judge's package metadata is intentionally left unchanged — it doesn't import numpy directly, and Colab already ships numpy, so this only needs fixing in the Docker image.Verification
jlpm installwith the same resolved versions (@jupyterlab/builder@4.5.8,webpack@5.107.2,license-webpack-plugin@4.0.2); instrumented the plugin to capture the offending identifier.--target labext-builder(linux/arm64, Node 20):build:prodfails without the patch, succeeds with it;third-party-licenses.jsonis generated and the wheel is produced.docker compose build): succeeds, andimport torchwith-W error::UserWarningis now clean —torch 2.12.0+cpu,numpy 2.4.6, interop OK.docker-publishCI rebuilds the image from scratch (thepackage.jsonchange busts thejlpm installlayer cache), independently validating both fixes onlinux/amd64.No automated tests are added: the repository has no test suite, and these are build/runtime-tooling fixes whose validation is the Docker build itself (run by CI on every PR).