From nodejs/node#32316 (comment)
Related: https://gist.github.com/WebReflection/8840ec29d296f2fa98d8be0102f08590#
Here’s how to create your own node-esm:
Create a file node-esm somewhere in your PATH, e.g. /usr/local/bin/node-esm:
#!/usr/bin/env sh
input_file=$1
shift
exec node --input-type=module - $@ <$input_file
Make it executable:
chmod +x /usr/local/bin/node-esm
Now you can save the following as a file like ./my-script:
#!/usr/bin/env node-esm
import { version } from 'process';
console.log(version);
And once it’s executable, it should work as you want:
$ chmod +x ./my-script
$ ./my-script
v13.12.0