phoenixframework / esbuild

An installer for esbuild
MIT License
271 stars 38 forks source link

install/0 fails when registry.npm.org is not accessible #26

Closed philippseith closed 3 years ago

philippseith commented 3 years ago

In an environment where registry.npm.org is not available, e.g. behind a corporate firewall where registry.npm.org is replaced by another npm registry, install/0 fails with:

[error] Task #PID<0.459.0> started from LiveviewDemoWeb.Endpoint terminating
** (RuntimeError) couldn't fetch https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.12.18.tgz: {:error, {:failed_connect, [{:to_address, {'registry.npmjs.org', 443}}, {:inet, [:inet], :nxdomain}]}}
    (esbuild 0.3.1) lib/esbuild.ex:226: Esbuild.fetch_body!/1
    (esbuild 0.3.1) lib/esbuild.ex:157: Esbuild.install/0
    (esbuild 0.3.1) lib/esbuild.ex:140: Esbuild.install_and_run/2
    (phoenix 1.6.0) lib/phoenix/endpoint/watcher.ex:19: Phoenix.Endpoint.Watcher.watch/2
    (elixir 1.12.2) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
    (stdlib 3.15.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Function: &Phoenix.Endpoint.Watcher.watch/2
    Args: ["esbuild", {Esbuild, :install_and_run, [:default, ["--sourcemap=inline", "--watch"]]}]

to prevent this, the host part of the url variable here https://github.com/phoenixframework/esbuild/blob/d4cf71f62f6c01234f8ab2d39467f1cce8dbeee7/lib/esbuild.ex#L157 should be made configurable

josevalim commented 3 years ago

A PR is definitely welcome!

philippseith commented 3 years ago

It turns out that using another npm registry boils down to implement all registry specific npm config keys like _auth, cert, strict-ssl and so on in fetch_body!/1. That would get complicated. I will try to add an install option which uses npm directly (and maybe one that uses golang)

josevalim commented 3 years ago

@philippseith those keys should not be required from our side but yeah, we will need an access to the SSL certificate. Another option is for you to configure the esbuild URL and we download from that URL. You can also download it and place it in _build/esbuild yourself. :)