-
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
v0.16.6 - failed to start esbuild if any ESM loader was present #2747
Comments
It would be incorrect to add a JavaScript file extension to
The underlying problem is that you're trying to run a binary executable through node. Don't do that. Just run it directly. Edit: Sorry, I missed that you're using Yarn. My comment above was for people who install esbuild with a non-Yarn package manager. The install script overwrites the JavaScript file you're referencing with a binary executable for speed, but it doesn't do this for Yarn because Yarn has bugs regarding binary executables as In any case, I'm not going to change the name of the |
Install esbuild and run it with any ESM loader. In this example, I use 'bin' script directly to avoid package manager related things. Loader is empty (which is valid according to specs - just no resolve / load hooks will be added to the chain):
From my understanding, the issue is related to the script extension (== no extension). It's OK for pure commonjs setup, but when we ask node to use loaders flow by --loader flag, node will execute defaultResolve / defaultLoad hooks for every incoming file. Next, defaultResolve can't handle files without extension, and return 'format: undefined' - which leads to fail inside defaultLoad.
'format: commonjs' at resolve stage (in my PoC I just test incoming url with '*/bin/esbuild' inside the hook) solves the issue - as per docs, it will activate some kind of CJS fallback. But it looks like a dirty hack )
So, proposed solution - to add .js (or even .cjs) extension to the 'bin' script (and change package.json too).
My use case (== 'why do you use loader here?') is simple - loader (simple ts transpiler) added for every 'yarn xxx' via NODE_OPTIONS yarn configuration, which is very useful for TS monorepo (no need to compile eslint / jest configs, etc.).
ps checked with node 18 too.
The text was updated successfully, but these errors were encountered: