The review step runs `npm ci` inside an npm workspace package, silently deleting the rest of the monorepo's dependencies

Open Beginner friendly
#1,633 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
tooling

Research direction

Start with src/programs/posthog-integration/agent/review.md at the frozen re-install instruction, then read the npm-specific install and workspace handling referenced in the issue. Check how the review step chooses its install command and whether the suggested npm ci --dry-run fits that flow. Done when the npm review check detects lockfile mismatches without removing dependencies from other workspace packages.

Written by the indexing model from the issue text.

Description

What happened

I ran the wizard (3.0.0) on an npm workspaces monorepo with --install-dir apps/web. The repo has one package-lock.json and one node_modules at the root, shared tools (typescript, @biomejs/biome, @playwright/test) as root devDependencies, and four workspace packages (apps/web, apps/server, apps/desktop, packages/shared).

During Verify and review the integration, the agent ran these from apps/web:

npm add posthog-js@1
npm ci                 # "npm's clean lockfile install check before compilation"
npm run build          # passed
npm run typecheck      # sh: tsc: command not found

Afterwards the root node_modules held only apps/web's dependency graph. typescript, @biomejs/biome, @playwright/test, electron and the other workspace links were gone. package-lock.json was unchanged, so git status showed nothing. Running npm install at the root restored everything.

The run summary said "verified a clean npm ci" and reported the typecheck as "unavailable because typescript is not declared in this package".

Why

src/programs/posthog-integration/agent/review.md asks for a frozen re-install after the last install:

https://github.com/PostHog/wizard/blob/f1cc489e38aae76e5e86a7b028861cdc9b284f5e/src/programs/posthog-integration/agent/review.md#L69-L72

After your last install, run the project's install once more without changing the lockfile (pnpm install --frozen-lockfile or its equivalent)

On npm the equivalent is npm ci, and with cd unavailable it runs in the workspace package. There npm scopes the command to that one package. npm ci deletes node_modules, then reinstalls only that package's dependencies. pnpm and yarn install the whole workspace from a sub-folder, so they don't have this problem.

The agent couldn't have worked around it:

  • The integration-build skill says to work only inside the project folder.
  • bash-fence.ts refuses directory flags that point outside it, so npm --prefix <root> ci isn't possible.
  • The agent's own detection ran from apps/web and saw a single-package repo, although the wizard's discovery had logged repoType=monorepo and detect_package_manager reported "the workspace lockfile is in ".
Minimal reproduction (npm 11.19.0, Node 24, macOS)
mkdir repro && cd repro && git init -q
cat > package.json <<'EOF'
{ "name": "repro", "private": true, "workspaces": ["apps/*"], "devDependencies": { "is-number": "7.0.0" } }
EOF
mkdir -p apps/web apps/api
echo '{ "name": "@repro/web", "version": "1.0.0", "private": true, "dependencies": { "ms": "2.1.3" } }' > apps/web/package.json
echo '{ "name": "@repro/api", "version": "1.0.0", "private": true, "dependencies": { "left-pad": "1.3.0" } }' > apps/api/package.json
npm install
ls node_modules                      # @repro  is-number  left-pad  ms
(cd apps/web && npm ci --dry-run)    # "up to date", nothing removed
(cd apps/web && npm ci)
ls node_modules                      # @repro  ms   <- is-number, left-pad and @repro/api are gone
Suggested fix

On npm, use npm ci --dry-run for the frozen re-check. It runs the same lockfile sync check as npm ci: when package.json and package-lock.json disagree, it fails with EUSAGE … Missing: <pkg> from lock file. It never deletes node_modules, it is safe from any workspace folder, and the bash fence already allows it.

It is weaker than a real npm ci in one way: a dry run downloads nothing and runs no install scripts, so a package whose download or install script would fail on a fresh install gets past it. On npm that gap is small: the npm add just before it had already downloaded the same packages and run their scripts. npm 11's allowScripts policy, its counterpart to pnpm's ignored build scripts, applies to that npm add as well, so a refused install script would show up there rather than in the dry run. Closing the gap would take a real npm ci from the workspace root. bash-fence.ts refuses directory flags outside the project folder, and that command would reinstall the whole monorepo.

 the project's install once more without changing the lockfile (`pnpm install
---frozen-lockfile` or its equivalent): if it fails on a package this run added, that package
+--frozen-lockfile`, `npm ci --dry-run` on npm,  or its equivalent): if it fails on a package this run added, that package
 does not fit.

Happy to test a fix against the same monorepo.

Dominant language
TypeScript
Stars
208
Forks
58
Avg merge
2d 7h
Merged PRs (30d)
76

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PostHog/wizard

All issues in PostHog/wizard

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.