Closed Yasser closed 2 years ago
Hi,
You should technically never need to run ./run yarn:build
manually. It only ever gets called in the package.json
file. It's meant to be something that gets run directly inside of the js
container, not from your terminal outside of Docker.
That is also brought up with its comment of: # Build JS assets, this is only meant to be referenced from your package.json
But since that works differently than the other run
commands, maybe I should turn both yarn:build
and yarn:build:css
into private functions by prefixing them with an underscore. That could get also get equally weird tho because they would be referenced in the package.json
file which implies they're not private.
Sorry, to clarify, I wasn't running them manually. This was with a docker compose up --build
Did you make any modifications to the Dockerfile or project?
Just asking because /app/node_modules/.bin/esbuild: cannot execute binary file
isn't a path that should exist. This project installs your Node modules to /node_modules
not /app/node_modules
.
No, the Dockerfile is the same as you have in master. A search through my project for '/app/node_modules' yields no results.
What OS are you using and what version of Docker / Docker Compose do you have?
I can't reproduce this here on both Windows and macOS by following the instructions in the readme:
nick@kitt ~ $ git clone https://github.com/nickjj/docker-rails-example /tmp/hellorails
Cloning into '/tmp/hellorails'...
remote: Enumerating objects: 718, done.
remote: Counting objects: 100% (718/718), done.
remote: Compressing objects: 100% (460/460), done.
remote: Total 718 (delta 394), reused 539 (delta 224), pack-reused 0
Receiving objects: 100% (718/718), 655.57 KiB | 10.57 MiB/s, done.
Resolving deltas: 100% (394/394), done.
nick@kitt ~ $ cd /tmp/hellorails
nick@kitt /tmp/hellorails (main) $ cp .env.example .env
nick@kitt /tmp/hellorails (main) $ cp docker-compose.override.yml.example docker-compose.override.yml
nick@kitt /tmp/hellorails (main) $ docker-compose up --build
[snipped out a lot of extra log output from building]
[these commands execute inside of the container]
$ ./run yarn:build:css
css_1 |
css_1 | Rebuilding...
css_1 | Done in 283ms.
yarn run v1.22.17
$ ./run yarn:build
js_1 | [watch] build finished, watching for changes...
At this point everything comes up successfully and I can access the site in a browser.
MacOS with Docker Desktop 3.5.2, Engine 20.10.7, Compose 1.29.2.
This is a project that I updated to Rails 7 then merged with your recent updates.
What happens if you follow the steps in my previous comment? Does it work?
Yes, installing clean from the repo works. I must have missed something in the update.
I would check your .yarnrc
file to make sure /node_modules
is set and then diff your Dockerfile vs mine.
Dockerfile is exact. .yarnrc
contains --modules-folder /node_modules
, as is should.
I'm not sure then, it's still installing things in a way where that .yarnrc
doesn't seem to have an effect because it's using /app/node_modules
. I'd carefully comb through the commit where I upgraded to Rails 7 https://github.com/nickjj/docker-rails-example/commit/2a8580a7dcfca7f278a55cd6ab6bd03838e7275e although I did change the run script a bit after that commit, all of which are listed at https://github.com/nickjj/docker-rails-example/commits/main.
If you're able to clone this repo and spin up the app successfully I think it's safe to say there's something in your app which is preventing this from working?
You could always do a docker-compose down && docker-compose build --no-cache && docker-compose up
on your end to give yourself a clean slate except for named volumes which will stick around such as for postgres. I don't think that will make a difference but it'll at least remove any notion that Docker is causing an issue with your custom app.
When in doubt you could diff the whole app too, not just the configuration looking for differences.
Fixed. For some reason, I had a hidden node_modules
folder in the root directory of my project. Removing that quickly solve my issue. Thanks for you help. Closing.
No problem, thanks for including what the resolution was.
When I build the project, my js compile fails with the following error:
$ ./run yarn:build js_1 | ./run: line 111: /app/node_modules/.bin/esbuild: cannot execute binary file: Exec format error js_1 | js_1 | Task completed in 0m0.024s error Command failed with exit code 126. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Manually reverting package.json to call
"esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds"
successfully compiles.