Closed10
rails7のアプリを/bin/devで起動したい
unknown command: yarn build:css --watch
エラーが発生して起動できない
package.jsonに追記
package.json
"scripts": {
"build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules",
"build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds"
}
エラー変わらず
yarnがinstallされていないことが原因のようなのでDockerfileに追記。
Dockerfile
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install -y yarn
sassが無いと怒られる
Installing foreman...
Successfully installed foreman-0.87.2
1 gem installed
13:36:03 web.1 | started with pid 18
13:36:03 css.1 | started with pid 20
13:36:03 css.1 | started with pid 22
13:36:03 css.1 | yarn run v1.22.19
13:36:03 css.1 | $ sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules --watch
13:36:03 css.1 | /bin/sh: 1: sass: not found
13:36:03 css.1 | error Command failed with exit code 127.
13:36:03 css.1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
13:36:04 css.1 | exited with code 127
13:36:04 system | sending SIGTERM to all processes
13:36:04 css.1 | rails aborted!
sassインストール
bundle exec rails css:install:sass
エラー発生
nodeのバージョンが古い模様
error sass@1.64.1: The engine "node" is incompatible with this module. Expected version ">=14.0.0". Got "12.22.12"
Dockerfileに下記追加
node14系指定
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get install -y nodejs \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install -y yarn
sassインストール
RUN yarn global add sass
tailwindcssを使いたかったのでコマンド修正
package.json
"build:css": "sass ./app/assets/stylesheets/application.tailwind.css:./app/assets/builds/application.css --no-source-map --load-path=node_modules --watch"
コンテナは起動するようになったが画面が表示されない
procfile.devの起動コマンドを修正
procfile.dev
- web: unset PORT && env RUBY_DEBUG_OPEN=true bin/rails server
+ web: unset PORT && env RUBY_DEBUG_OPEN=true bin/rails server -b 0.0.0.0
起動成功!
このスクラップは2023/07/23にクローズされました