Closed philippseith closed 2 years ago
Hi @philippseith! Thanks for the PR but I would prefer to not depend on the precise mechanics of npm install
. Based on your PR, I pushed a tiny configuration that allows the path to be configured. In your app, you would be to do this:
config :esbuild,
path: System.get_env("MIX_ESBUILD_PATH")
Now you can do npm install -g esbuild
and make it point precisely to the esbuild path. Please give it a try and let me know!
Cool, that's much simpler. But: It works on linux but on Windows there are some quirks.
there is
where.exe esbuild`setx MIX_ESBUILD_PATH C:\\Users\\...\\AppData\\Roaming\\npm\\esbuild
C:\\Users\\...\\AppData\\Roaming\\npm\\esbuild
was the output of where.exe esbuild
and causes
** (ErlangError) Erlang error: :eacces
erlang.erl:2217: :erlang.open_port({:spawn_executable, 'C:\\Users\\...\\AppData\\Roaming\\npm\\esbuild'}, [:use_stdio, :exit_status, :binary, :hide, {:args, ["--version"]}])
(elixir 1.12.3) lib/system.ex:1052: System.do_cmd/3
There seems to be a problem executing *.cmd files with Erlang. A workaround is to call cmd.exe /c MIX_ESBUILD_PATH
instead or setting MIX_ESBUILD_PATH to the location of esbuild.exe. But esbuild.exe is not in path but in ...\npm\node_modules\esbuild
BTW: The test fails here (both on linux and windows) https://github.com/phoenixframework/esbuild/blob/6c73497492adfa19a513da7145c160bcd59019c6/test/esbuild_test.exs#L21 when the installed version is different to the one required from the test
@philippseith Yeah, the reason why cmd
fails is because where.exe esbuild
is not pointing to esbuild, but rather a shim escript that executes esbuild. Pointing to esbuild.exe
is the way to go. I have changed the docs in this commit to clarify that: https://github.com/phoenixframework/esbuild/commit/6c73497492adfa19a513da7145c160bcd59019c6
The config key :installmode controls how the esbuild executable is downloaded and installed.
By using an existing npm installation, the problems mentioned in https://github.com/phoenixframework/esbuild/issues/26#issuecomment-929834668 are circumvented. Furthermore, the already working npm configuration, including a custom registry and all its security and authentication settings is used.