phoenixframework/phoenix

tailwind config doesn't respect MIX_DEPS_PATH

ericlathrop opened this issue · 2 comments

Environment

  • Elixir version (elixir -v): 1.17.2
  • Phoenix version (mix deps): 1.7.14
  • Operating system: alpine linux (the elixir:1.17.2-alpine docker container)

Context

I'm building a docker container to run my phoenix app in a dev environment. In the container I install the code at /app, which is a volume shared with my laptop so I can edit the code there. Also, I have a volume at /deps where I want the deps installed, so I used MIX_DEPS_PATH to accomplish this. I want the deps to be in an isolated volume to prevent conflicts on the laptop.

If I just put the volume at /app/deps, then if the laptop has installed deps those will get imported from the laptop into the volume just once at creation, and you get into a world of weird errors because they don't always update.

So I use MIX_DEPS_PATH to make it work.

Actual behavior

When running mix assets.build while MIX_DEPS_PATH is set outside of the app, you get this error:

$ mix assets.build

Rebuilding...
Error: ENOENT: no such file or directory, scandir '/app/deps/heroicons/optimized/24/outline'
    at Object.readdirSync (node:fs:1405:3)
    at Object.readdirSync (pkg/prelude/bootstrap.js:1309:35)
    at /app/assets/tailwind.config.js:45:12
    at Array.forEach (<anonymous>)
    at /app/assets/tailwind.config.js:44:13
    at registerPlugins (/snapshot/tailwindcss/lib/lib/setupContextUtils.js:815:61)
    at createContext (/snapshot/tailwindcss/lib/lib/setupContextUtils.js:1221:5)
    at createContext (/snapshot/tailwindcss/lib/processTailwindFeatures.js:44:61)
    at Object.getContext (/snapshot/tailwindcss/lib/cli/build/plugin.js:200:24)
    at /snapshot/tailwindcss/lib/cli/build/plugin.js:247:38 {
  errno: -2,
  syscall: 'scandir',
  code: 'ENOENT',
  path: '/app/deps/heroicons/optimized/24/outline'
}
** (Mix) `mix tailwind my_app` exited with 1

This is probably from this line:

let iconsDir = path.join(__dirname, "..<%= if @in_umbrella, do: "/../.." %>/deps/heroicons/optimized")

which doesn't seem to respect MIX_ENV_PATH.

A similar issue was reported in #5414.

Expected behavior

I expect mix assets.build to work when MIX_ENV_PATH is set to a directory other than the usual path.

If I manually change

let iconsDir = path.join(__dirname, "..<%= if @in_umbrella, do: "/../.." %>/deps/heroicons/optimized")
to fix the path, I run into the #5414 issue, which still exists. If I edit config/config.exs to fix that, then mix assets.build runs successfully.

As per #5414, this is not a common scenario, so we don't plan to include this boilerplate out of the box for new apps. But thank you for documenting your steps, it can help others in the future. Just note it is MIX_DEPS_PATH and not MIX_ENV_PATH. :)