Skip to content

[Bug] SyntaxError when running a "bin" file that isn't authored in JS #882

@cameronhunter

Description

@cameronhunter
  • I'd be willing to implement a fix

Describe the bug

Yarn 2.0 fails with a SyntaxError when running a bin file that isn't authored in JS. For example, the bin file may be an executable file with a shebang #!/usr/bin/env sh.

Example bin file:

#!/usr/bin/env sh
echo 'Hello world!'

To Reproduce

See sample package (@cameronhunter/berry-bin-bug) that defines a bin that is an executable file with a shebang.

const { promises: { writeFile, chmod } } = require('fs');

await writeFile('./hello-world', '#!/usr/bin/env sh\necho "Hello world!"');
await chmod('./hello-world', 0o765);

await packageJsonAndInstall({
  bin: { 'hello-world': './hello-world' }
});

await expect(yarn('hello-world')).resolves.toContain('Hello world!');

Example of failure:

$ yarn berry-bin-bug
/Users/chunter/workspace/github/cameronhunter/berry-bin-bug/bin/berry-bin-bug:3
echo "Hello world!"
     ^^^^^^^^^^^^^^

SyntaxError: Unexpected string
    at Module._compile (internal/modules/cjs/loader.js:895:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.module_1.Module._load (/Users/chunter/workspace/github/cameronhunter/berry-bin-bug/.pnp.js:13519:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11

Environment if relevant (please complete the following information):

  • OS: MacOS Mojave (10.14.5)
  • Node version: 12.14.0
  • Yarn version: 2.0.0-rc.28

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreproducibleThis issue can be successfully reproduced

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions