Skip to content

export() leaves out large files npm wrote that nothing has read yet #2180

Open

Description

@iamarunbrahma

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

  1. Boot a WebContainer and mount this package.json with the package-lock.json npm 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"
      }
    }
  2. Run npm ci there and wait for it to exit with 0. (We ran it in a folder under node_modules, cwd: 'node_modules/.fresh', so the dev server's watcher ignored it; the result is the same.)
  3. 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' });
  4. List every file with its size in both folders (a small node -e script with fs.readdirSync and fs.statSync), then compare the two lists. The 15 files above are missing from the copy.
  5. Run npm ci again. 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

  1. github-actions commented on Nov 5, 2026

    @github-actions

    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.

  2. SamVerschueren commented on Nov 6, 2026

    @SamVerschueren
    Contributor

    Hey @iamarunbrahma! The reason for this is that large files are lazy. We leave them out of node_modules until 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 export was never designed to export node_modules. If you want to rehydrate, make sure you have a package-lock.json and because of browser caching that install should be very fast.

    What's your use case for exporting node_modules?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions