Skip to content

--watch-path restarts on unrelated directory touch when --env-file is set #61906

@OliverJAsh

Description

@OliverJAsh

Version

  • Node.js: v24.13.0
  • OS: macOS

Reproduction

Setup:

mkdir -p /tmp/node-watch-envfile-repro/watched /tmp/node-watch-envfile-repro/unrelated
cd /tmp/node-watch-envfile-repro

echo "FOO=bar" > .env

echo "console.log('START', JSON.stringify({ pid: process.pid, ts: Date.now(), foo: process.env.FOO ?? null }));" > watched/server.js
echo "setInterval(() => {}, 1000);" >> watched/server.js

Run with --env-file and touch an unrelated path:

cd /tmp/node-watch-envfile-repro

node --watch-path=watched --env-file=.env watched/server.js > out-env.log 2>&1 &
PID=$!

sleep 2
touch unrelated
sleep 2

kill $PID
cat out-env.log

Observed output:

START {"pid":58939,"ts":1771621917212,"foo":"bar"}
Restarting 'watched/server.js'
START {"pid":58948,"ts":1771621919442,"foo":"bar"}

Now run without --env-file:

cd /tmp/node-watch-envfile-repro

node --watch-path=watched watched/server.js > out-no-env.log 2>&1 &
PID=$!

sleep 2
touch unrelated
sleep 2

kill $PID
cat out-no-env.log

Observed output:

START {"pid":59279,"ts":1771621950778,"foo":null}

Expected behavior

When --watch-path=watched is set, touching unrelated should not trigger a restart, regardless of whether --env-file is used.

Actual behavior

With --env-file=.env, touching unrelated triggers a restart.
Without --env-file, touching unrelated does not restart.

Notes

This was first noticed in a larger workspace where:

node --watch-path=apps/server/dist-dev --env-file=.env apps/server/dist-dev/server.js

restarts when running:

touch apps/client/dist/

The reduced test case above reproduces the same behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions