saleor / storefront

Saleor Storefront built with React 18, Next.js 14, App Router, TypeScript, GraphQL, and Tailwind CSS.
https://storefront.saleor.io
BSD 3-Clause "New" or "Revised" License
1.01k stars 585 forks source link

Can't build the container image during `pnpm build` #1050

Closed matejak closed 8 months ago

matejak commented 9 months ago

Summary

When building from the Dockerfile, the build ends with following errors:

[3/4] STEP 12/12: RUN pnpm build

> saleor-storefront@0.1.0 prebuild /app
> pnpm run generate

> saleor-storefront@0.1.0 generate /app
> graphql-codegen --config .graphqlrc.ts

[STARTED] Parse Configuration
[SUCCESS] Parse Configuration
[STARTED] Generate outputs
[STARTED] Generate to src/gql/
[STARTED] Load GraphQL schemas
error: unknown option '--config'
 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.

I have no idea about what could possibly cause this, I am not too familiar with web development, and what puzzled me is that I couldn't even find any reference to pnpm build.

Steps to reproduce

Checkout the storefront project, main branch, 57dfc2c52a76f010ff150060f2a73bbb32eb3d46 on 10th of Dec 2023. Add context: . under build in the docker-compose.yml Build the container image using docker-compose with correct build args.

A link to a reproduction repository

No response

Output from envinfo

No response

matejak commented 9 months ago

@mmiszy Hello, it looks like that this is your level of expertise.

jdmueller commented 8 months ago

I am having this same issue. I have followed the directions: cloned the repo, cp .env.example to .env, I have run pnpm i. When I create a docker image of this repo it fails with the same reason/text/error above from original poster. I saw also that the .env file was being ignored by the .gitignore file and even changing this does not fix it. It has been 3 years since I worked with a saleor store and I am not sure what I could be doing wrong since the directions seem simple enough to follow. I have used this process for Saleor and Dashboard and they create the docker images without any errors.

2024-01-10T16:04:12Z > [builder 6/6] RUN pnpm build: 2024-01-10T16:04:12Z #22 1.681 > pnpm run generate 2024-01-10T16:04:12Z #22 1.681 2024-01-10T16:04:12Z #22 2.895 2024-01-10T16:04:12Z #22 2.895 > saleor-storefront@0.1.0 generate /app 2024-01-10T16:04:12Z #22 2.895 > graphql-codegen --config .graphqlrc.ts 2024-01-10T16:04:12Z #22 2.895 2024-01-10T16:04:12Z #22 5.155 Before GraphQL types can be generated, you need to set NEXT_PUBLIC_SALEOR_API_URL environment variable. 2024-01-10T16:04:12Z #22 5.157 Follow development instructions in the README.md file. 2024-01-10T16:04:12Z #22 5.223  ELIFECYCLE  Command failed with exit code 1. 2024-01-10T16:04:12Z #22 5.246  ELIFECYCLE  Command failed with exit code 1. 2024-01-10T16:04:12Z ------ 2024-01-10T16:04:12Z ERROR: failed to solve: executor failed running [/bin/sh -c pnpm build]: exit code: 1 2024-01-10T16:04:12Z Build failed using Buildkit (1)

I have this being built within the hub.docker system straight from my GitHub repo.

I understand that I have to run the container with arguments and env variables but if the container itself will not build in the docker system there is no way to run the image using with the arguments such as NEXT_PUBLIC_SALEOR_API_URL.

I got this same error when running this from my M2 Mac and as soon as I specify this variable in my terminal it runs without any issue.

jdmueller commented 8 months ago

@matejak Were you ever able to resolve this?

jdmueller commented 8 months ago
Screenshot 2024-01-10 at 5 12 37 PM

I have even specified these in the build variables section of the hub.docker system and the build still fails. I don't understand why the other 2 images (Saleor 3.18 and Dashboard 3.18) will build correctly but this one does not.

matejak commented 8 months ago

Thank you for the pointer, I have set the build args incorrectly, and I got no complaints, however the build has failed in that weird way. With correct build arguments, it works :-) I wouldn't say that the issue is fixed or invalid, as a small typo can lead one completely astray.

@jdmueller I guess that what you are after are build arguments, and not env variables. Env vars are overriden with build args in the Dockerfile. I am not familiar with the build system that you are using though.

jdmueller commented 8 months ago

@matejak I am using the hub.docker.com system that automatically generates an image file from my GitHub responistory whenever there is a push to the master. This builds a new image automatically and I can just restart the service and it automatically runs the new build. I have found this to work great for everything. And it works for the other 2 repos from saleor, but for some reason not this one. It even builds the image correctly without changing the .env file from .env.example. I just don't have enough experience with docker to understand what is going on or why it wouldn't even build the image. I haven't even tried to run it yet.

jdmueller commented 8 months ago

So I have created a new issue that specifies my problem since it sounds like the issue should be closed as you were able to figure out your problem. My issue is more specific to hub.docker.com.

matejak commented 8 months ago

Well, I close this as my issue is indeed resolved. Anybody looking for the solution - pay attention to contents of your build arguments, make sure that they point to where the README says they should, and that those URLs are available from your build environment.