-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
esbuild error on WSL (Ubuntu 20.04.1 LTS - Windows 10) / via yarn 2 #467
Comments
Strangely it works when I install esbuild-windows-64, WSL 2 is supposed to run native linux binary... |
I don't use yarn myself, but it appears to me that however you are running it is causing the binary executable to be interpreted as JavaScript code. I once came across a strange page on the yarn repo that seemed to indicate that yarn 2 is deliberately incompatible with binary executables: yarnpkg/berry#882. This seems kind of unbelievable to me so I'm not sure if it's true. But could that be the case here? If so, it could be that you could get it to work by changing how you are invoking it perhaps (no ideas for what to try, sorry), or by using esbuild's JavaScript API instead of the command-line interface. You could also consider using a different package manager if that still doesn't work. If not, you could try providing more details here about how exactly you are running esbuild in case that makes something stand out. Edit: Actually it looks like a similar issue has already been filed here in the past: #237. That's where I learned about this from. That thread may also have some useful information. |
Correct - in practice exceedingly few packages directly use binaries in their const {spawnSync} = require(`child_process`);
const {status} = spawnSync(`${__dirname}/file.exe`, [], {stdio: `inherit`});
process.exitCode = status || 1; We could reconsider, but to be honest I believe this is the first package that got hurt by this behaviour in the past year, so I'm not convinced restoring the heuristic would be worth it. Would the bridge I shared be an acceptable solution on your side? |
Thanks for the context. I deliberately did not add a bridge file because node has additional startup overhead and I'm trying to keep esbuild as fast and lightweight as possible. I don't think it's appropriate to slow down esbuild for everyone just because Yarn 2 doesn't support this. Other package managers support this fine (e.g. npm, pnpm, Yarn 1). Since npm is the official package manager for node, it's also my officially-supported package manager for esbuild. People can use other package managers if they want to but they may have issues to the extent that those package managers aren't compatible with npm/node. For example, esbuild will not include support for Yarn 2's custom path resolution since that's not part of how npm/node works. I'll add a note to the docs about Yarn 2 not supporting invoking esbuild directly. As you said, it's easy enough to work around for people that need to use Yarn 2 for other reasons. |
One random idea I had: in the install script I could try to detect that esbuild is being installed via Yarn 2 and attempt to work around this issue by generating the shim only for Yarn 2. Is there a way to tell if a package is being installed by Yarn 2? |
Hm that should be possible - the
|
Just for my own curiosity: I see you do this on Windows, any specific reason for that? |
Btw, slightly off-topic, while I understand why you wouldn't want to add builtin support for PnP, do you think it would be possible to add a message if a bare identifier resolution fails, no resolver plugin is configured, and you detect the existence of a
This would avoid people having to Google-search the solution, since they'll have to solve this anyway one way or another 🤔 |
I wonder if berry could support native executables on an opt-in basis using an inexpensive heuristic such as file extension. It might be a somewhat strange and possibly confusing constraint, but at the same time it's likely better than the current hard requirement of JS bin entries. There'd be potentially less overhead and it might lessen the burden for packages like esbuild to conform to the requirements of berry. |
I'm not sure it would help since in this case the intent is to have either a JS or a native binary depending on the circumstances, so the extension would necessarily be the same 🤔 I'll keep this issue in mind, perhaps we'll find a way to safely relax this requirement. It got implemented extremely early on (part of the first thirteen commits of the new Yarn codebase), and while I don't exactly remember why I made it this way it was probably more accidental than really on purpose. |
This should work now as of version 0.8.3. |
I appear to now have this exact issue with regular NPM. Otherwise same configuration and same output.
I worked around it by creating a js wrapper with |
Hey @evanw, I was just thinking about this issue. Would you be interested if Yarn supported directly spawning binaries if their extension is (Note that we can't require the [edit] We're also discussing internally whether we could just read the first few bytes and check for its magic number / shebang line. That would avoid you having to make any change at all, provided the perf overhead is reasonable. |
After creating fresh yarn 2 project. install esbuild as usual, and then run it:
The text was updated successfully, but these errors were encountered: