phoenixframework / tailwind

An installer for tailwind
MIT License
475 stars 61 forks source link

Failed to deploy with `mix tailwind default --minify` exited with 1 #38

Closed alaadahmed closed 1 year ago

alaadahmed commented 2 years ago

I don't know why I get this error?

=> ERROR [builder 15/19] RUN mix assets.deploy                                                                       16.5s
------
 > [builder 15/19] RUN mix assets.deploy:
#24 1.717 
#24 1.717 23:43:45.075 [debug] Downloading tailwind from https://github.com/tailwindlabs/tailwindcss/releases/download/v3.0.24/tailwindcss-linux-x64
#24 16.31 node:internal/modules/cjs/loader:933
#24 16.31   const err = new Error(message);
#24 16.31               ^
#24 16.31 
#24 16.31 Error: Cannot find module 'tailwindcss-textshadow'
#24 16.31 Require stack:
#24 16.31 - /app/assets/tailwind.config.js
#24 16.31 - /snapshot/tailwindcss/lib/cli.js
#24 16.31 - /snapshot/tailwindcss/standalone-cli/standalone.js
#24 16.31 1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
#24 16.31     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
#24 16.31     at Function._resolveFilename (pkg/prelude/bootstrap.js:1819:46)
#24 16.31     at Function.Module._load (node:internal/modules/cjs/loader:778:27)
#24 16.31     at Module.require (node:internal/modules/cjs/loader:1005:19)
#24 16.31     at Module.require (pkg/prelude/bootstrap.js:1719:31)
#24 16.31     at Module.require (/snapshot/tailwindcss/standalone-cli/standalone.js:21:22)
#24 16.31     at require (node:internal/modules/cjs/helpers:94:18)
#24 16.31     at Object.<anonymous> (/app/assets/tailwind.config.js:25:5)
#24 16.31     at Module._compile (node:internal/modules/cjs/loader:1101:14)
#24 16.31     at Module._compile (pkg/prelude/bootstrap.js:1758:32) {
#24 16.31   code: 'MODULE_NOT_FOUND',
#24 16.31   requireStack: [
#24 16.31     '/app/assets/tailwind.config.js',
#24 16.31     '/snapshot/tailwindcss/lib/cli.js',
#24 16.31     '/snapshot/tailwindcss/standalone-cli/standalone.js'
#24 16.31   ],
#24 16.31   pkg: true
#24 16.31 }
#24 16.33 ** (Mix) `mix tailwind default --minify` exited with 1
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c mix assets.deploy]: exit code: 1

I read in README here that if I needed to use 3rd party plugin for Tailwind then I need to install node, and I did that. Here is my package.json file:

{
  "devDependencies": {
    "postcss": "^8.4.12",
    "tailwindcss": "^3.0.24",
    "tailwindcss-rtl": "^0.9.0",
    "tailwindcss-textshadow": "^2.1.3"
  },
  "dependencies": {
    "@fontsource/inter": "^4.5.7",
    "@fontsource/noto-kufi-arabic": "^4.5.6"
  }
}

I also thought to install tailwindcss itself as node package thinking this would help, that's why you will find it above in the package.json file, but I also tried at first without installing it and just installed the only 2 3rd party plugins I needed tailwindcss-rtl & tailwindcss-text-shadow! But it seems my tailwind.config.js doesn't feel these 3rd party plugins!!

Screen Shot 2022-04-19 at 01 48 35

I get this error when I deploy to Fly.io, and this is my Dockerfile

#EASA ATPL Theory Distance Learning + Refresh Cours Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of
# Alpine to avoid DNS resolution issues in production.
#
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
# https://hub.docker.com/_/ubuntu?tab=tags
#
#
# This file is based on these images:
#
#   - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
#   - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image
#   - https://pkgs.org/ - resource for finding needed packages
#   - Ex: hexpm/elixir:1.13.4-erlang-24.3.3-debian-bullseye-20210902-slim
#
ARG ELIXIR_VERSION=1.13.4
ARG OTP_VERSION=24.3.3
ARG DEBIAN_VERSION=bullseye-20210902-slim

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

FROM ${BUILDER_IMAGE} as builder

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git curl \
    software-properties-common \
    npm

RUN npm install npm@latest -g && \
    npm install n -g && \
    n lts

# prepare build dir
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
    mix local.rebar --force

# set build ENV
ENV MIX_ENV="prod"
ENV NODE_ENV="production"

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile

COPY priv priv

COPY lib lib

COPY assets assets
RUN NODE_ENV=$NODE_ENV npm install --prefix assets

# compile assets
RUN mix assets.deploy

# Compile the release
RUN mix compile

# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/

COPY rel rel
RUN mix release

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}

RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales \
  && apt-get clean && rm -f /var/lib/apt/lists/*_*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

WORKDIR "/app"
RUN chown nobody /app

# set runner ENV
ENV MIX_ENV="prod"

# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/gat ./

USER nobody

CMD ["/app/bin/server"]
alaadahmed commented 2 years ago

Deploy success when I remove these two 3rd party plugins from tailwind.config.js

Darth-Knoppix commented 2 years ago

I'm seeing an exit for a slightly different error resulting in a failure to build on an M1 device on Tailwind 3.0.24 in a new Phoenix 1.6.7 project:

❯ mix tailwind default
node:internal/modules/package_json_reader:4
const internalModuleReadJSON = function (f) { return require('fs').internalModuleReadJSON(f); };
                                                                   ^

TypeError: require(...).internalModuleReadJSON is not a function
    at internalModuleReadJSON (node:internal/modules/package_json_reader:4:68)
    at Object.read (node:internal/modules/package_json_reader:21:42)
    at readPackage (node:internal/modules/cjs/loader:296:36)
    at readPackageScope (node:internal/modules/cjs/loader:329:19)
    at trySelf (node:internal/modules/cjs/loader:444:40)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:910:24)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1276:12)
    at loadPrelonode:internal/modules/package_json_reader:4
const internalModuleReadJSON = function (f) { return require('fs').internalModuleReadJSON(f); };
                                                                   ^

TypeError: require(...).internalModuleReadJSON is not a function
    at internalModuleReadJSON (node:internal/modules/package_json_reader:4:68)
    at Object.read (node:internal/modules/package_json_reader:21:42)
    at readPackage (node:internal/modules/cjs/loader:296:36)
    at readPackageScope (node:internal/modules/cjs/loader:329:19)
    at trySelf (node:internal/modules/cjs/loader:444:40)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:910:24)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1276:12)
    at loadPreloadModules (node:internal/bootstrap/pre_execution:487:5)
** (Mix) `mix tailwind default` exited with 1

mix tailwind default through Rosetta (x86) works as expected, doing this as a workaround

josevalim commented 1 year ago

Yes, this package does not support third party plugins. Then you must use Tailwind from npm.