phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.41k stars 2.87k forks source link

tailwind config doesn't respect MIX_DEPS_PATH #5890

Closed ericlathrop closed 3 months ago

ericlathrop commented 3 months ago

Environment

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: https://github.com/phoenixframework/phoenix/blob/2920eb281ad78f06c3c5f3fd5afb02f175562172/installer/templates/phx_assets/tailwind.config.js#L36 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.

ericlathrop commented 3 months ago

If I manually change https://github.com/phoenixframework/phoenix/blob/2920eb281ad78f06c3c5f3fd5afb02f175562172/installer/templates/phx_assets/tailwind.config.js#L36 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.

josevalim commented 3 months ago

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. :)