Repository navigation
Description
Describe the bug
After npm ci in a WebContainer, webcontainer.export('node_modules', { format: 'binary' }) returns a snapshot that leaves out some of the large files npm just wrote. Mounting that snapshot into another folder gives 7,989 of the 8,004 files. The same 15 files are missing on every run, and all of them are 1 MB or larger:
@esbuild/linux-x64/bin/esbuild 11427952
@rollup/rollup-linux-x64-gnu/rollup.linux-x64-gnu.node 2186624
@rollup/rollup-linux-x64-musl/rollup.linux-x64-musl.node 2211496
@tailwindcss/oxide-linux-x64-gnu/tailwindcss-oxide.linux-x64-gnu.node 2997400
@tailwindcss/oxide-linux-x64-musl/tailwindcss-oxide.linux-x64-musl.node 3015776
lightningcss-linux-x64-gnu/lightningcss.linux-x64-gnu.node 10040456
lightningcss-linux-x64-musl/lightningcss.linux-x64-musl.node 10036152
lucide-react/dist/cjs/lucide-react.js.map 5590556
lucide-react/dist/lucide-react.d.ts 2196411
lucide-react/dist/lucide-react.prefixed.d.ts 2108349
lucide-react/dist/lucide-react.suffixed.d.ts 2104455
lucide-react/dist/umd/lucide-react.js.map 5694830
lucide-react/dist/umd/lucide-react.min.js.map 4402684
lucide-react/dynamic.d.ts 2286301
lucide-react/dynamicIconImports.d.ts 2285089
Not every large file is dropped: typescript/lib/typescript.js (9 MB) is kept. Waiting 5 seconds before exporting doesn't change the result, but reading each file of 1 MB or more first does. A one-byte read with node's fs inside the container, taking about 0.5 s for these 29 files, makes the export complete (8,004 of 8,004). So it looks as if a file npm wrote but nothing has read since isn't visible to export().
In practice, an app restored from such a snapshot has no type declarations for lucide-react, so tsc fails on every icon import.
Link to the blitz that caused the error
None. This reproduces with @webcontainer/api 1.6.4 calls directly, in a page that boots a WebContainer; the steps below are the whole repro.
Steps to reproduce
- Boot a WebContainer and mount this
package.jsonwith thepackage-lock.jsonnpm writes for it:{ "type": "module", "dependencies": { "class-variance-authority": "0.7.1", "cn": "0.5.0", "lucide-react": "0.577.0", "radix-ui": "1.8.1", "react": "19.2.9", "react-dom": "19.2.9" }, "devDependencies": { "@tailwindcss/vite": "4.3.3", "@types/react": "19.2.18", "@types/react-dom": "19.2.7", "@vitejs/plugin-react": "5.2.0", "tailwindcss": "4.3.3", "tw-animate-css": "1.4.0", "typescript": "5.9.3", "vite": "7.3.7" } } - Run
npm cithere and wait for it to exit with 0. (We ran it in a folder undernode_modules,cwd: 'node_modules/.fresh', so the dev server's watcher ignored it; the result is the same.) - Export the installed folder and mount it into another one:
const snapshot = await webcontainer.export('node_modules/.fresh/node_modules', { format: 'binary' }); await webcontainer.fs.mkdir('node_modules/.copy', { recursive: true }); await webcontainer.mount(snapshot, { mountPoint: 'node_modules/.copy' });
- List every file with its size in both folders (a small
node -escript withfs.readdirSyncandfs.statSync), then compare the two lists. The 15 files above are missing from the copy. - Run
npm ciagain. This time, before exporting, open each file of 1 MB or more in the installed folder and read one byte. Then repeat step 3: the copy now has every file.
Expected behavior
export() returns every file in the folder, as fs.readdir and fs.stat inside the container see them.
Parity with Local
export() and mount() exist only in WebContainer, so there is nothing to compare locally. Inside the container, fs.readdir and fs.stat list all 8,004 files before the export.
Platform
- OS: macOS 26.5
- Browser: Chrome 156.0.8078.81
- @webcontainer/api: 1.6.4 (Node v24.22.2 in the container)
Activity
github-actions commentedon Nov 5, 2026
We noticed that you did not provide a StackBlitz or Bolt reproduction link. Please update the issue and add a link to a public project.
SamVerschueren commentedon Nov 6, 2026
Hey @iamarunbrahma! The reason for this is that large files are lazy. We leave them out of
node_modulesuntil something reads it to reduce browser memory pressure, to increase speed, and to avoid downloading files you never need. It doesn't make sense to download a native addon because we don't run native addons.The
exportwas never designed to exportnode_modules. If you want to rehydrate, make sure you have apackage-lock.jsonand because of browser caching that install should be very fast.What's your use case for exporting
node_modules?