Skip to content

fix(dev-scripts): absolutize NODE_OPTIONS --require for portless cwd#1292

Merged
vklimontovich merged 1 commit into
newjitsufrom
fix/env-preload-portless-cwd
May 9, 2026
Merged

fix(dev-scripts): absolutize NODE_OPTIONS --require for portless cwd#1292
vklimontovich merged 1 commit into
newjitsufrom
fix/env-preload-portless-cwd

Conversation

@vklimontovich
Copy link
Copy Markdown
Contributor

Summary

pnpm console:dev / pnpm ee-api:dev (and pnpm ui:dev) crash on startup with Cannot find module 'env-preload'.

Root cause: root .npmrc sets node-options=--require=env-preload, so every pnpm-spawned node process inherits NODE_OPTIONS=--require=env-preload. dev-scripts/src/bin/run-app.ts then spawns portless with cwd: SHIM_DIR — a non-git scratch dir deliberately outside any node_modules — to dodge portless's hardcoded worktree subdomain prefix. portless is itself a node binary; it tries to load env-preload from SHIM_DIR and dies in loadPreloadModules before the inner bash ever runs.

Fix: rewrite --require=NAME (and -r NAME) tokens in NODE_OPTIONS to absolute paths via createRequire(import.meta.url).resolve() before spawning portless. With absolute paths the cwd switch is harmless; both portless and the inner next dev get the preload.

Portless has no flag, env var, or config field to disable the worktree prefix on its run / <name> <cmd> paths (--no-worktree exists only on portless get), so SHIM_DIR has to stay.

Test plan

  • pnpm typecheck:turbo --filter=@jitsu-internal/dev-scripts clean
  • pnpm console:dev boots: portless logs -> https://console-<branch>.jitsu.localhost, Next reports Ready in <ms>
  • pnpm ui:dev boots both console and ee-api
  • pnpm console:dev --no-branch still works on the bare host

`pnpm console:dev` / `pnpm ee-api:dev` (and `pnpm ui:dev`) crash on
startup with `Cannot find module 'env-preload'`.

Root cause: the root .npmrc sets `node-options=--require=env-preload`
so every pnpm-spawned node process inherits
`NODE_OPTIONS=--require=env-preload`. run-app.ts spawns portless with
`cwd: SHIM_DIR` (a non-git scratch dir, deliberately outside any
`node_modules`) to dodge portless's hardcoded worktree subdomain
prefix. portless is itself a node binary; it tries to load
`env-preload` from `SHIM_DIR` and dies in `loadPreloadModules`
before the inner bash ever runs.

Fix: rewrite `--require=NAME` (and `-r NAME`) tokens in NODE_OPTIONS
to absolute paths via `createRequire(import.meta.url).resolve()` before
spawning portless. With absolute paths, the cwd switch is harmless;
both portless and the inner `next dev` get the preload.

Portless has no flag, env var, or config field to disable the worktree
prefix on its `run` / `<name> <cmd>` paths (only `portless get` honors
`--no-worktree`), so SHIM_DIR has to stay.
Copy link
Copy Markdown

@jitsu-code-review jitsu-code-review Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks correct and addresses the portless startup regression when NODE_OPTIONS contains bare --require entries (notably env-preload from .npmrc). The resolver logic is scoped, preserves unresolved modules, and keeps existing behavior for non-require options.

@vklimontovich vklimontovich merged commit f5664bd into newjitsu May 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant