External assets in productoin

The app compiles locally and runs on localhost:4000

but in prod, via fly deploy , I can’t manage external .js files in assets.
The error is

✘ [ERROR] Could not resolve "highlight.js/lib/core"
#21 10.71
#21 10.71     js/highlighter.js:1:17:
#21 10.71       1 │ import hljs from 'highlight.js/lib/core';
#21 10.71         ╵                  ~~~~~~~~~~~~~~~~~~~~~~~
#21 10.71
#21 10.71   You can mark the path "highlight.js/lib/core" as external to exclude it from the bundle, which will remove this error.
#21 10.71

How does one include external .js files in assets.deploy?

My mix.exs is

defp aliases do
    [
      "assets.deploy": [
        "tailwind default --minify",
        "esbuild default --minify",
        "phx.digest"
      ],
      setup: [
        "deps.get",
        "cmd npm --prefix assets install"
      ]
    ]
  end

It’s months later, but if I helps I found the solution for this was to teach the fly.io docker container about npm.

Make the following changes to Dockerfile to add npm as a build dependency and execute npm install before compiling the assets.

- RUN apt-get update -y && apt-get install -y build-essential git \
+ RUN apt-get update -y && apt-get install -y build-essential git npm \
RUN cd assets && npm install   # <--- add this line

# compile assets
RUN mix assets.deploy
3 Likes