-
Notifications
You must be signed in to change notification settings - Fork 43
shebang: #!/usr/bin/env node
— a BOM
issue
#464
Comments
I assume the same thing happens if the file is called |
One quick meta note is that V8 should support the shebang natively and IIRC our module implementation depends on that. So it feels really weird that it would be platform-dependent..? |
Tried on my mac (version installed via $ node test.js
(node:12797) ExperimentalWarning: The ESM module loader is experimental.
file:///tmp/shebang/test.js darwin
$ node -v
v13.6.0
$ cat test.js
#!/usr/bin/env node
import {platform} from 'os';
console.log(import.meta.url, platform()); |
Ah, missed P.S.: |
Still, same result after running as CJS (removing my bad type field from package.json): $ cat test.js
#!/usr/bin/env node
const {platform} = require('os');
console.log(platform());
$ node test.js
darwin
$ node -v
v13.6.0 |
I haven't tried debugging this, but I remember that earlier versions of our loader included Node stripping out the shebang line; I think when V8 added support for it, Node's code was removed. So there might be a bug in V8 shebang handling. |
@SMotaal does your file start with a utf8 byte order mark?
|
Is it intended that a starting BOM would not be removed as part of the shebang? |
it shouldn't be removed as part of the hashbang, but i'm surprised that node doesn't strip utf8 bom when reading source files anymore. |
I am inclined to say it is an OS problem:
|
which is more disturbing honestly :) |
I guess I used UTF-16 at some point and decided it was still to much hassle and went to UTF-8 which technically should not need BOM — ah living in the 🙃 But that issue comes up a lot apparently elsewhere too. Okay, while we are here let's ask, folks, what is the recommended encode setting for ESM files? |
#!/usr/bin/env node
(macOS)#!/usr/bin/env node
— a BOM
issue
#!/usr/bin/env node
— a BOM
issue#!/usr/bin/env node
— a BOM
issue
Thanks folks! |
I assume everything should be utf-8 everywhere always, but it still seems like a BOM should be stripped. |
@ljharb I think the problem is the OS is not stripping it, hence never called node — https://en.wikipedia.org/wiki/Shebang_(Unix)#Magic_number +1 on UTF-8 — just can't recall why I was inclined to add BOMs exactly (assuming it was latent from UTF-16 bugging in Windows, but since moved to UTF-8) |
This issues related to the issue seen with rewire (jhnns/rewire#179) Would somebody be able to clarify how this issue relates please? |
@mbwhite seems like that is due to this refactoring PR being backported - https://github.com/nodejs/node/pull/27768/files. |
Folks, quick question about shebang on macOS!
Package:
~/blah/blah/package.json
Module:
~/blah/blah/blah.js
Command:
node blah.js # in ~/blah/blah
Checks:
Module:
~/blah/blah/blah.js
Command:
node blah.js # in ~/blah/blah
The text was updated successfully, but these errors were encountered: