node-dev icon indicating copy to clipboard operation
node-dev copied to clipboard

divergent behavior between `node <script>` and `node-dev <script>`

Open cdaringe opened this issue 3 years ago • 7 comments

Problem

  • node myscript.js emits events and logs, but node-dev myscript.js does not.

Reproduction

I've produced a tiny reproduction with minimal but complete instructions here: https://github.com/cdaringe/node-dev-divergent-behavior-workers#demo

  1. run without node-dev: npm run start-without-node-dev
[demo]: running worker method (type: function)
[demo]: error - logged without node-dev, not logged with node-dev Error: bummer, i'm caught in index.ts
[demo]: event - logged without node-dev, not logged with node-dev. Error: bummer, i'm caught in index.ts
  1. run with node-dev: npm start
[demo]: running worker method (type: function)

and the process exits (awaiting respawn, if respawn used)

cdaringe avatar Apr 16 '22 23:04 cdaringe

The jest-worker is using the copying execArgv (--require=/path/to/wrap.js, --experimental-loader=...), which is breaking their worker. I modified the worker source to ignore these options and it went fine :). perhaps these modules can apply a bit of defense to noop unless they are the entry processes 🤔

cdaringe avatar Apr 17 '22 03:04 cdaringe

node-dev my-script

  • node -r wrap.js --expiremental-loader=... my-script.js { env: { IS_NODE_DEV_ENTRY: 1 } }
/* wrap.js */ 
if (IS_NODE_DEV_ENTRY) { 
  delete process.env.IS_NODE_DEV_ENTRY;  // critically, flag this file as a noop in the future!
  doTheNormalWrapStuff()
} else { 
  /* noop */ 
}

cdaringe avatar Apr 17 '22 03:04 cdaringe

I cloned the repo, ran npm install then:

❯ npm run start

> [email protected] start
> node-dev --respawn index.ts

[demo]: running worker method (type: function)
[demo]: error - logged without node-dev, not logged with node-dev Error: bummer, i'm caught in index.ts
[demo]: event - logged without node-dev, not logged with node-dev. Error: bummer, i'm caught in index.ts
^C%  

I'm not seeing the behavior that you're describing.

bjornstar avatar Apr 17 '22 05:04 bjornstar

hmm. that's odd. i'm getting the same result on two different machines.

image

Maybe we could compare envs?

npx envinfo:

  System:
    OS: macOS 11.6
    CPU: (8) arm64 Apple M1
    Memory: 220.23 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 17.1.0 - /var/folders/p0/7478zjgn41scns83dcs60c7h0000gn/T/fnm_multishells/32026_1650178274430/bin/node
    Yarn: 1.22.17 - /var/folders/p0/7478zjgn41scns83dcs60c7h0000gn/T/fnm_multishells/32026_1650178274430/bin/yarn
    npm: 8.1.2 - /var/folders/p0/7478zjgn41scns83dcs60c7h0000gn/T/fnm_multishells/32026_1650178274430/bin/npm
  Managers:
    Cargo: 1.61.0 - ~/.cargo/bin/cargo
    Homebrew: 3.4.3 - /opt/homebrew/bin/brew
    pip3: 21.3.1 - /opt/homebrew/bin/pip3
    RubyGems: 3.0.3 - /usr/bin/gem
  Utilities:
    Make: 3.81 - /usr/bin/make
    GCC: 4.2.1 - /usr/bin/gcc
    Git: 2.30.1 - /usr/bin/git
    Clang: 13.0.0 - /usr/bin/clang
    FFmpeg: 5.0 - /opt/homebrew/bin/ffmpeg
  Servers:
    Apache: 2.4.48 - /usr/sbin/apachectl
  Virtualization:
    Docker: 20.10.12 - /usr/local/bin/docker
  IDEs:
    Nano: 2.0.6 - /usr/bin/nano
    VSCode: 1.66.1 - /opt/homebrew/bin/code
    Vim: 8.2 - /usr/bin/vim
    Xcode: /undefined - /usr/bin/xcodebuild
  Languages:
    Bash: 3.2.57 - /bin/bash
    Perl: 5.30.2 - /usr/bin/perl
    PHP: 7.3.29 - /usr/bin/php
    Python: 2.7.16 - /usr/bin/python
    Python3: 3.9.10 - /opt/homebrew/bin/python3
    Ruby: 2.6.3 - /usr/bin/ruby
    Rust: 1.61.0 - /Users/cdaringe/.cargo/bin/rustc
  Databases:
    SQLite: 3.32.3 - /usr/bin/sqlite3
  Browsers:
    Chrome: 100.0.4896.88
    Firefox: 98.0.2
    Safari: 14.1.2

cdaringe avatar Apr 17 '22 06:04 cdaringe

I'm using node v17.9.0, I tried 17.1.0 and it exhibited the same behavior you described. I don't particularly want to spend more time on debugging the issue, it works on the latest version of 16 and 17.

bjornstar avatar Apr 17 '22 07:04 bjornstar

I went from “not having a node bug since 8.x” to two in the last month. So infrequent that I rarely remember to even check the node version! 😀

Thanks for running it

On Sun, Apr 17, 2022 at 12:45 AM Bjorn Stromberg @.***> wrote:

I'm using node v17.9.0, I tried 17.1.0 and it exhibited the same behavior you described. I don't particularly want to spend more time on debugging the issue, it works on the latest version of 16 and 17.

— Reply to this email directly, view it on GitHub https://github.com/fgnass/node-dev/issues/288#issuecomment-1100824703, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHU57JURQ3NRFK2CX4BHCDVFO6QZANCNFSM5TTA37EA . You are receiving this because you authored the thread.Message ID: @.***>

-- Sent from Gmail Mobile

cdaringe avatar Oct 11 '22 08:10 cdaringe

@cdaringe This sounds a lot like https://github.com/nodejs/node/issues/41134, which caused the following issue on Jest: https://github.com/facebook/jest/issues/12060

Try upgrading to Node.js v14.19.2, v16.14, or v17.4 if you're currently using an older version

kherock avatar Jan 16 '23 05:01 kherock