node icon indicating copy to clipboard operation
node copied to clipboard

Node 20.13 --watch option breaks loader / preload of modules

Open ecamellini opened this issue 9 months ago • 0 comments

Version

v20.13.1

Platform

Darwin chaos.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

1) Create a TS app with an index.js, ts-node to use as loader, and a module to preload

mkdir testapp
cd testapp
echo "console.log('Hello World!');" > index.ts
npm i --save ts-node
npm i --save dotenv-flow

2) Launch one of the following commands

node --watch --loader ts-node/esm ./src/index.ts
node --watch -r 'dotenv-flow/config' ./src/index.ts

How often does it reproduce? Is there a required condition?

It can be reproduced deterministically with the steps outlined above on version 20.13. The condition required to reproduce it is to put --watch as the first option.

If you run the following, the bug is not present:

node --loader ts-node/esm --watch ./src/index.ts
node  -r 'dotenv-flow/config' --watch ./src/index.ts

The error seems to not be present neither in 20.12 nor in >=21: it happens only on 20.13 / 20.13.1

What is the expected behavior? Why is that the expected behavior?

The program should run, print Hello World!, then remain in watch mode waiting for file changes.

What do you see instead?

Error: Cannot find module - node seems to not look for modules in the node_modules folder.

Additional information

No additional info.

ecamellini avatar May 22 '24 15:05 ecamellini