Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run script from the console with UTF-8 with BOM #39111

Open
arteze opened this issue Jun 22, 2021 · 3 comments
Open

Run script from the console with UTF-8 with BOM #39111

arteze opened this issue Jun 22, 2021 · 3 comments
Labels
module Issues and PRs related to the module subsystem.

Comments

@arteze
Copy link

arteze commented Jun 22, 2021

From Linux I make a script with shebang:

#!/bin/node

// Code...

But when I transformed it to UTF-8 with BOM it does not run.

line 1: ���#!/bin/node: No such file or directory

Seeing this I just realized that it is a problem of the terminal and not of Node, but if I run it with Node, the problem is still.

node script.js

Answer in LxTerminal:

���#!/bin/node

Answer on Sakura:

#!/bin/node
 ^

SyntaxError: Invalid or unexpected token
    at Object.compileFunction (node:vm:353:18)
    at wrapSafe (node:internal/modules/cjs/loader:1039:15)
    at Module._compile (node:internal/modules/cjs/loader:1073:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47
@arteze arteze changed the title Run Script from the console with UTF-8 with BOM Run script from the console with UTF-8 with BOM Jun 22, 2021
@targos
Copy link
Member

targos commented Jun 22, 2021

This is expected behavior. See #27768

@arteze
Copy link
Author

arteze commented Jun 22, 2021

I see that one of the /test/fixtures folder works well.

curl -O https://raw.githubusercontent.com/nodejs/node/master/test/fixtures/utf8-bom.js

Hexdump of utf8-bom.js:

hexdump -C utf8-bom.js
00000000  ef bb bf 6d 6f 64 75 6c  65 2e 65 78 70 6f 72 74  |...module.export|
00000010  73 20 3d 20 34 32 3b 0a                           |s = 42;.|
00000018
  • The file utf8-bom.js It works well.
  • The file utf8-bom-shebang-shebang.js it does not work.
  • The file utf8-shebang-bom.js also, it works perfect.

Hexdump of utf8-shebang-bom.js

hexdump -C utf8-shebang-bom.js
00000000  23 21 73 68 65 62 61 6e  67 0a ef bb bf 6d 6f 64  |#!shebang....mod|
00000010  75 6c 65 2e 65 78 70 6f  72 74 73 20 3d 20 34 32  |ule.exports = 42|
00000020  3b                                                |;|
00000021

Hexdump replicating my script:

hexdump -C ./test_she.js
00000000  ef bb bf 23 21 73 68 65  62 61 6e 67 0a 6d 6f 64  |...#!shebang.mod|
00000010  75 6c 65 2e 65 78 70 6f  72 74 73 20 3d 20 34 32  |ule.exports = 42|
00000020  3b 0a                                             |;.|

This fails while the one in fixtures works well.

@targos
Copy link
Member

targos commented Aug 9, 2021

I don't really know how to label this or who to ping, except @devsnek who worked on #27768

@Mesteery Mesteery added the module Issues and PRs related to the module subsystem. label Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module Issues and PRs related to the module subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants