node_modules/node-sass: Command failed を解決したい
こんにちは。Dockerを用いてrails:6以降でローカル環境を作りたいと思っています。
しかし、rails new するといつも「error /study_app/node_modules/node-sass: Command failed.」とエラーが出てしまい、ローカル環境で index のページに飛ぶことができません。(rails の画面には遷移可能)
エラーを出さなくするためのアドバイスを頂きたいです。よろしくお願いいたします。
発生している問題・エラーメッセージ
error /study_app/node_modules/node-sass: Command failed.
作成した Gemfile (Gemfile.lock も中身空で作成)
source 'https://rubygems.org' gem 'rails', '~> 6.0.0'
作成した Dockerfile
FROM ruby:2.7 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs default-mysql-client vim 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 update \ && apt install --no-install-recommends -y yarn RUN mkdir /study_app WORKDIR /study_app COPY Gemfile /study_app/Gemfile COPY Gemfile.lock /study_app/Gemfile.lock RUN bundle install COPY . /study_app
作成した docker-compose.yml
version: '3' services: db: platform: linux/x86_64 image: mysql:5.7 networks: - ruby000net1 volumes: - mysql_data:/var/lib/mysql ports: - "3306:3306" environment: MYSQL_ROOT_PASSWORD: myrootpass MYSQL_USER: user web: build: . command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" depends_on: - db networks: - ruby000net1 volumes: - .:/study_app/ ports: - 3000:3000 networks: ruby000net1: volumes: mysql_data:
rails new の実行(以下ターミナル)
docker-compose run web rails new . --force --database=mysql
Gemfile の bundle install
docker-compose build
dbに以下を追加
password: myrootpass host: db
コンテナ起動
docker-compose up -d
db 作成
docker-compose exec web rails db:create
rails new のタイミングで以下のようにエラー文と付随した箇所の出現
yarn add v1.22.15 info No lockfile found. [1/4] Resolving packages... warning @rails/webpacker > node-sass > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 warning @rails/webpacker > node-sass > node-gyp > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 warning @rails/webpacker > node-sass > request > har-validator@5.1.5: this library is no longer supported warning @rails/webpacker > node-sass > request > uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. warning @rails/webpacker > node-sass > node-gyp > tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap. warning @rails/webpacker > webpack > watchpack > watchpack-chokidar2 > chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies. warning @rails/webpacker > webpack > watchpack > watchpack-chokidar2 > chokidar > fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2. warning @rails/webpacker > webpack > node-libs-browser > url > querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. warning @rails/webpacker > postcss-preset-env > postcss-color-functional-notation > postcss-values-parser > flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash. warning @rails/webpacker > optimize-css-assets-webpack-plugin > cssnano > cssnano-preset-default > postcss-svgo > svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x. warning @rails/webpacker > webpack > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated warning @rails/webpacker > webpack > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated [2/4] Fetching packages... info fsevents@2.3.2: The platform "linux" is incompatible with this module. info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation. info fsevents@1.2.13: The platform "linux" is incompatible with this module. info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... [4/4] Building fresh packages... [-/2] ⡀ waiting... error /study_app/node_modules/node-sass: Command failed. Exit code: 1 Command: node scripts/build.js Arguments: Directory: /study_app/node_modules/node-sass Output: Building: /usr/local/bin/node /study_app/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= gyp info it worked if it ends with ok gyp verb cli [ gyp verb cli '/usr/local/bin/node', gyp verb cli '/study_app/node_modules/node-gyp/bin/node-gyp.js', gyp verb cli 'rebuild', gyp verb cli '--verbose', gyp verb cli '--libsass_ext=', gyp verb cli '--libsass_cflags=', gyp verb cli '--libsass_ldflags=', gyp verb cli '--libsass_library=' gyp verb cli ] gyp info using node-gyp@3.8.0 gyp info using node@15.10.0 | linux | arm64 gyp verb command rebuild [] gyp verb command clean [] gyp verb clean removing "build" directory gyp verb command configure [] gyp verb check python checking for Python executable "python2" in the PATH gyp verb `which` failed Error: not found: python2 gyp verb `which` failed at getNotFoundError (/study_app/node_modules/which/which.js:13:12) gyp verb `which` failed at F (/study_app/node_modules/which/which.js:68:19) gyp verb `which` failed at E (/study_app/node_modules/which/which.js:80:29) gyp verb `which` failed at /study_app/node_modules/which/which.js:89:16 gyp verb `which` failed at /study_app/node_modules/isexe/index.js:42:5 gyp verb `which` failed at /study_app/node_modules/isexe/mode.js:8:5 gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:196:21) gyp verb `which` failed python2 Error: not found: python2 gyp verb `which` failed at getNotFoundError (/study_app/node_modules/which/which.js:13:12) gyp verb `which` failed at F (/study_app/node_modules/which/which.js:68:19) gyp verb `which` failed at E (/study_app/node_modules/which/which.js:80:29) gyp verb `which` failed at /study_app/node_modules/which/which.js:89:16 gyp verb `which` failed at /study_app/node_modules/isexe/index.js:42:5 gyp verb `which` failed at /study_app/node_modules/isexe/mode.js:8:5 gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:196:21) { gyp verb `which` failed code: 'ENOENT' gyp verb `which` failed } gyp verb check python checking for Python executable "python" in the PATH gyp verb `which` failed Error: not found: python gyp verb `which` failed at getNotFoundError (/study_app/node_modules/which/which.js:13:12) gyp verb `which` failed at F (/study_app/node_modules/which/which.js:68:19) gyp verb `which` failed at E (/study_app/node_modules/which/which.js:80:29) gyp verb `which` failed at /study_app/node_modules/which/which.js:89:16 gyp verb `which` failed at /study_app/node_modules/isexe/index.js:42:5 gyp verb `which` failed at /study_app/node_modules/isexe/mode.js:8:5 gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:196:21) gyp verb `which` failed python Error: not found: python gyp verb `which` failed at getNotFoundError (/study_app/node_modules/which/which.js:13:12) gyp verb `which` failed at F (/study_app/node_modules/which/which.js:68:19) gyp verb `which` failed at E (/study_app/node_modules/which/which.js:80:29) gyp verb `which` failed at /study_app/node_modules/which/which.js:89:16 gyp verb `which` failed at /study_app/node_modules/isexe/index.js:42:5 gyp verb `which` failed at /study_app/node_modules/isexe/mode.js:8:5 gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:196:21) { gyp verb `which` failed code: 'ENOENT' gyp verb `which` failed } gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable. gyp ERR! stack at PythonFinder.failNoPython (/study_app/node_modules/node-gyp/lib/configure.js:484:19) gyp ERR! stack at PythonFinder.<anonymous> (/study_app/node_modules/node-gyp/lib/configure.js:406:16) gyp ERR! stack at F (/study_app/node_modules/which/which.js:68:16) gyp ERR! stack at E (/study_app/node_modules/which/which.js:80:29) gyp ERR! stack at /study_app/node_modules/which/which.js:89:16 gyp ERR! stack at /study_app/node_modules/isexe/index.js:42:5 gyp ERR! stack at /study_app/node_modules/isexe/mode.js:8:5 gyp ERR! stack at FSReqCallback.oncomplete (node:fs:196:21) gyp ERR! System Linux 5.10.47-linuxkit gyp ERR! command "/usr/local/bin/node" "/study_app/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd /study_app/node_modules/node-sass gyp ERR! node -v v15.10.0 gyp ERR! node-gyp -v v3.8.0 gyp ERR! not ok Build failed with error code: 1
試したこと
・Dockerfile 内で node.js の version を15.10に指定
・rails の version を3まで上げる
・コンテナが Webpacker に入っているか確認
・他サイトの記事を参考に rails new のタイミングで Webpacker のインストールを指定した。
など
自分が version などの正しい上げ方を熟知していないため上げ方などが間違っているかもしれません。
あなたの回答
tips
プレビュー