fix(dev-scripts): absolutize NODE_OPTIONS --require for portless cwd#1292
Merged
Conversation
`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.
There was a problem hiding this comment.
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.
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.
Summary
pnpm console:dev/pnpm ee-api:dev(andpnpm ui:dev) crash on startup withCannot find module 'env-preload'.Root cause: root
.npmrcsetsnode-options=--require=env-preload, so every pnpm-spawned node process inheritsNODE_OPTIONS=--require=env-preload.dev-scripts/src/bin/run-app.tsthen spawns portless withcwd: SHIM_DIR— a non-git scratch dir deliberately outside anynode_modules— to dodge portless's hardcoded worktree subdomain prefix. portless is itself a node binary; it tries to loadenv-preloadfromSHIM_DIRand dies inloadPreloadModulesbefore the inner bash ever runs.Fix: rewrite
--require=NAME(and-r NAME) tokens inNODE_OPTIONSto absolute paths viacreateRequire(import.meta.url).resolve()before spawning portless. With absolute paths the cwd switch is harmless; both portless and the innernext devget the preload.Portless has no flag, env var, or config field to disable the worktree prefix on its
run/<name> <cmd>paths (--no-worktreeexists only onportless get), soSHIM_DIRhas to stay.Test plan
pnpm typecheck:turbo --filter=@jitsu-internal/dev-scriptscleanpnpm console:devboots: portless logs-> https://console-<branch>.jitsu.localhost, Next reportsReady in <ms>pnpm ui:devboots both console and ee-apipnpm console:dev --no-branchstill works on the bare host