-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Bug] SyntaxError when running a "bin" file that isn't authored in JS #882
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This issue reproduces on master:
|
That would be a wontfix as third-party binaries aren't portable and cannot be run from zip archives. At worst, you can make a JS script that uses |
Thanks for your response, @arcanis. Cross-platform isn't a goal for many of our (internal) tools so it's a shame that we have to spin up node to execute a shebang executable. I can certainly work around this using your suggestion though. Perhaps this ticket could be changed to focus on improving the error message so that other users don't fall into the same confusion. Side-question: Is cross-platform portability a goal of berry or is it more the implementation detail of not being able to run them from zip archives? |
A bit of both - I'd say the main reason is that we'd like to encourage applications to avoid using shell scripts as it puts the burden on users (installs take more time, and zero installs don't work). So if you want to absolutely do it, better do it explicitly. |
Some NPM packages (e.g., https://www.npmjs.com/package/elm) are meant to provide a native binary executable for various platforms and expose it so that it can be found via PATH when run from a script specified in package.json (often indirectly, e.g., via a specific loader for webpack). These packages cannot be used with Yarn Berry, even with Can Yarn provide a configuration option to skip the shell script shim for a particular executable? |
Is there away to run TypeScript I used #!npx esr --cache as shebang with "name": "@comp/scripts",
"bin": {
"my-script": "./src/cli/my-script.ts"
} in the Surely I could compile the script to JS first, but it was a quite nice developer experience to just execute the TS file without having a build step always in between.. |
I agree with @ti1024. More and more packages are providing native binaries (Rust, Go), and not having these work via Yarn is a huge problem IMO. What if yarn inspected the |
btw, this worked in yarn v1 too |
Hi, I encountered a similar problem now. I installed the richard@MacBook-Pro coffeebot % yarn ngrok
/Users/richard/vl/bots/coffeebot/.yarn/unplugged/ngrok-npm-4.3.1-f30055099e/node_modules/ngrok/bin/ngrok:1
����
SyntaxError: Invalid or unexpected token
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1026:15)
at Module._compile (node:internal/modules/cjs/loader:1061:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.external_module_.Module._load (/Users/richard/vl/bots/coffeebot/.pnp.cjs:13342:14)
at Function.moduleExports.runMain (/Users/richard/vl/bots/coffeebot/.pnp.cjs:13543:31)
at node:internal/main/run_main_module:17:47
Node.js v17.4.0 I also tried However, I found a workaround here: evanw/esbuild#237 (comment) Running "ngrok": "$(yarn bin ngrok)", Now the |
I'm facing the same issue with some elm tools (elm-test & elm-review), the proposed workaround seems doesn't work in this case
any news on this? |
In my opinion native binaries should be supported, at least on unplugged packages. Someone should step in, implement and maintain this feature - yes, of course. At least it should not be viewed as wont fix. |
The package Its "bin": {
"composer": "./composer.phar"
}
#!/usr/bin/env php
<?php It seems that the shebang line is actually parsed when running
But when I define a script in my project like this: "scripts": {
"foo": "composer --version"
}
|
I found a workaround though. If I define my script like this, it will execute correctly: "scripts": {
"foo": "node_modules/.bin/composer --version"
} |
Hello! This thread has been discussing two separate issues.
It's a little difficult to follow the thread with those two separate issues kept together, so I think it's best to keep it archived. However, since the second use case is not resolved yet (a Another reason why I'd like another thread to be opened is to assess how important is this use case in practice. While supporting native binaries were clearly high value (I'm aware of a couple of packages who had to make workarounds for Yarn), I'm not quite convinced the same is true for non-JS shebang scripts. We had some internal debates, and settling them would benefit from having clear example of semi-popular packages using such patterns - so far, we don't have any in mind, hence why we'd need your help. |
Hello! Trunk is affected by this as well.
|
Hi, as indicated in mklement0/ttab#52, @rtrembecky's workaround FYI, I even run yarn 4 workspaces command for my mono-repo like this: TTAB=$(yarn bin ttab) yarn workspaces foreach -A exec '$TTAB -G exec yarn start' |
Describe the bug
Yarn 2.0 fails with a
SyntaxError
when running abin
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:To Reproduce
See sample package (
@cameronhunter/berry-bin-bug
) that defines abin
that is an executable file with a shebang.Example of failure:
Environment if relevant (please complete the following information):
10.14.5
)12.14.0
2.0.0-rc.28
The text was updated successfully, but these errors were encountered: