Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker - @symfony/ux-swup/package.json not found #37

Open
adrienlamotte opened this issue Mar 25, 2021 · 3 comments
Open

Docker - @symfony/ux-swup/package.json not found #37

adrienlamotte opened this issue Mar 25, 2021 · 3 comments

Comments

@adrienlamotte
Copy link

I have a docker for my Symfony 5 project, but I can't make it work with @symfony/ux-swup. When I try to build with npm run build, I have the error bellow in Docker :

Step #0:  error  in ./assets/controllers.json
Step #0: Syntax Error: Error: The file "@symfony/ux-swup/package.json" could not be found. Try running "yarn install --force".

Here is my docker file relevant parts :

FROM composer:1.9 as build
WORKDIR /app/
COPY composer.json composer.lock /app/
RUN composer global require hirak/prestissimo && \
    composer install

# ------------------------------------------------------

FROM php:7.4.5-apache
RUN apt-get update && apt-get install -y 

COPY --from=build /app/vendor /var/www/app/vendor

WORKDIR /var/www/app
COPY . /var/www/app/

# ------------------------------------------------------

FROM node:12-alpine
WORKDIR /var/www/app

COPY package*.json webpack.config.js /var/www/app/
COPY assets /var/www/app/assets

RUN npm install && \
    npm run build

I have noticed that in the package.js, ux-swup il referenced by :

"@symfony/ux-swup": "file:vendor/symfony/ux-swup/Resources/assets",

Not sure if this might cause the problem...

Any clues?
Thanks!

@tgalopin
Copy link
Contributor

Hi Adrien!

I just encountered this issue and it was due to invalid Yarn cache in my home directory. Perhaps is it linked here too?

@jvancoillie
Copy link

Hello @adrienlamotte, @tgalopin 👋

I found myself faced with the same problem, the "node build stage" of the assets requires having the vendor directory present due to the definition of the ux-chartjs in the package.json file

"@symfony/ux-chartjs" : "file:vendor/symfony/ux-chartjs/Resources/assets" 

For this, I added a "composer" build step that I then copy into my node and php stage as follows:

ARG PHP_VERSION=8.1
ARG CADDY_VERSION=2
ARG NODE_VERSION=17
ARG COMPOSER_VERSION=2

# ==========================================================================================
#           --- COMPOSER ---
# ==========================================================================================
FROM composer:${COMPOSER_VERSION} AS symfony_composer

WORKDIR /srv/app

COPY composer.json composer.lock symfony.lock ./

RUN composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress;

# ==========================================================================================
#           --- NODE ---
# ==========================================================================================
FROM node:${NODE_VERSION}-alpine AS symfony_node

WORKDIR /srv/app

COPY package*.json ./
## Here copy vendor directory needed for ux-chartjs build on assets build.
COPY --from=symfony_composer /srv/app/vendor vendor/ 

RUN yarn install

## copy everything to use PostCSS, Tailwinds, webpack, ...
COPY . .

RUN yarn run build

# ==========================================================================================
#           --- PHP ---
# ==========================================================================================

FROM php:${PHP_VERSION}-fpm-alpine AS symfony_php

// ...

COPY --from=symfony_composer /usr/bin/composer /usr/bin/composer

ENV COMPOSER_ALLOW_SUPERUSER=1

ENV PATH="${PATH}:/root/.composer/vendor/bin"

WORKDIR /srv/app

COPY --from=symfony_node /srv/app/public/build public/build

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]

I think there is better to do, that's why I share my solution with you.

@mahererais
Copy link

mahererais commented Apr 25, 2024

  • project symfony 6.4 :
  • i had the error message Error: The file "@symfony/ux-swup/package.json" could not be found. when a tried to build with npm run build after install Symfony UX Swup
  • i didn't have the line "@symfony/ux-swup": "file:vendor/symfony/ux-swup/Resources/assets" on my package.json file.
  • so i added, and i alrealy had an error message when build.
  • check your vendor you vendor/symfony/ux-swup/, i noticed that i didn't have Ressource directory
    image
  • remove previous line and add "@symfony/ux-swup": "file:vendor/symfony/ux-swup/assets"
  • build and it's work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants