### Version v24.11.1 ### Platform ```text Linux academic 6.1.0-32-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.129-1 (2025-03-06) x86_64 GNU/Linux ``` ### Subsystem _No response_ ### What steps will reproduce the bug? Create a `package.json` containing only `{}`. Create the following file `script` and chmod it executable. (Note that it's ESM, not CommonJS.) ``` #!/usr/bin/env node console.log('script STARTED') import { version } from 'node:process' console.log(version) ``` In that same directory, run the script and observe that it produces the expected output and "success" exit code: ``` $ ./script ; echo "===== exitcode=$?" script STARTED v24.11.1 ===== exitcode=0 ``` Now add to your `package.json` the line `"type": "commonjs"`. Run the script again, and note that it produces no output at all (neither what it is expected to print nor any errors), and yet still exits with exit code 0, indicating success: ``` $ ./script ; echo "===== exitcode=$?" ===== exitcode=0 ``` If you feel like it, you can replace the ESM import with `const { version } = require('node:process')` and see that it does work as in the first example run above. ### How often does it reproduce? Is there a required condition? Always reproduces. ### What is the expected behavior? Why is that the expected behavior? I expect the `"type": "commonjs"` case to do two things, in order of importance: 1. Exit with a non-zero exit code (indicating "failure") because it didn't run. This would help avoid the especially insidious situation where it's a script running in a build system that's expected to do something important but produce no output. (Ask me how I know this is "insidious." :-)) 2. Print some sort of error to stderr indicating that the script can't be run, ideally including some information about the configuration that's preventing this. (In this case, I guess, it's that the auto-detection of ESM vs. CommonJS based on file contents is disabled due to the `"type": "commonjs"` in `package.json`?) ### What do you see instead? See output in reproduction above. ### Additional information `node --print-all-exceptions ./script >exceptions.txt 2>&1` may have some useful information in its 1240 lines. I've attached the output from my machine as [`exceptions.txt`](https://github.com/user-attachments/files/24227368/exceptions.txt). Also, possibly #49444 "Feature: ESM in executable files" may have some relation to this, though I've not read through it carefully (it's a long read).