LoginSignup
9
2

More than 1 year has passed since last update.

M1MacでDocker環境にnode-sass入れようとしたらエラー出たから解決した

Last updated at Posted at 2021-09-01

はじめに

環境を新しくしようとM1Mac買って(安かったから)ウキウキしながら開発を再構築していたら、node-sass周りでエラーになりやがりまして解決した時のやり方です。

前提

以下のようなdockerファイルでnode環境にnode-sass(Ver4.14.1)を入れようとしています。
他にももちろん入れようとしていますが、node-sass周り以外のエラーはなかったので、問題ないもしくは同様の対処で問題が解消されたようです。

# 使用するDokcerfile
FROM node:12.10-slim

RUN mkdir /workspace
COPY ./package.json /workspace/package.json

WORKDIR /workspace
RUN npm install

ただ、最初に出たエラーは以下のように404エラーだったんですが、今日やったら別のエラーになっていました。これについては謎ですが、一時的な問題だったのかもしれません。

# 最初に出たエラー
Cannot download "https://github.com/sass/node-sass/releases/download/v4.14.1/linux-arm64-72_binding.node": 
# 記事書いた日に出たエラー
#11 18.16 > node-sass@4.14.1 postinstall /workspace/node_modules/node-sass
#11 18.16 > node scripts/build.js
#11 18.16 
#11 18.23 Building: /usr/local/bin/node /workspace/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
#11 18.27 gyp info it worked if it ends with ok
#11 18.27 gyp verb cli [
#11 18.27 gyp verb cli   '/usr/local/bin/node',
#11 18.27 gyp verb cli   '/workspace/node_modules/node-gyp/bin/node-gyp.js',
#11 18.27 gyp verb cli   'rebuild',
#11 18.27 gyp verb cli   '--verbose',
#11 18.27 gyp verb cli   '--libsass_ext=',
#11 18.27 gyp verb cli   '--libsass_cflags=',
#11 18.27 gyp verb cli   '--libsass_ldflags=',
#11 18.27 gyp verb cli   '--libsass_library='
#11 18.27 gyp verb cli ]
#11 18.27 gyp info using node-gyp@3.8.0
#11 18.27 gyp info using node@12.10.0 | linux | arm64
#11 18.27 gyp verb command rebuild []
#11 18.27 gyp verb command clean []
#11 18.27 gyp verb clean removing "build" directory
#11 18.27 gyp verb command configure []
#11 18.28 gyp verb check python checking for Python executable "python2" in the PATH
#11 18.28 gyp verb `which` failed Error: not found: python2
#11 18.28 gyp verb `which` failed     at getNotFoundError (/workspace/node_modules/which/which.js:13:12)
#11 18.28 gyp verb `which` failed     at F (/workspace/node_modules/which/which.js:68:19)
#11 18.28 gyp verb `which` failed     at E (/workspace/node_modules/which/which.js:80:29)
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/which/which.js:89:16
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/isexe/index.js:42:5
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/isexe/mode.js:8:5
#11 18.28 gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:169:21)
#11 18.28 gyp verb `which` failed  python2 Error: not found: python2
#11 18.28 gyp verb `which` failed     at getNotFoundError (/workspace/node_modules/which/which.js:13:12)
#11 18.28 gyp verb `which` failed     at F (/workspace/node_modules/which/which.js:68:19)
#11 18.28 gyp verb `which` failed     at E (/workspace/node_modules/which/which.js:80:29)
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/which/which.js:89:16
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/isexe/index.js:42:5
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/isexe/mode.js:8:5
#11 18.28 gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:169:21) {
#11 18.28 gyp verb `which` failed   stack: 'Error: not found: python2\n' +
#11 18.28 gyp verb `which` failed     '    at getNotFoundError (/workspace/node_modules/which/which.js:13:12)\n' +
#11 18.28 gyp verb `which` failed     '    at F (/workspace/node_modules/which/which.js:68:19)\n' +
#11 18.28 gyp verb `which` failed     '    at E (/workspace/node_modules/which/which.js:80:29)\n' +
#11 18.28 gyp verb `which` failed     '    at /workspace/node_modules/which/which.js:89:16\n' +
#11 18.28 gyp verb `which` failed     '    at /workspace/node_modules/isexe/index.js:42:5\n' +
#11 18.28 gyp verb `which` failed     '    at /workspace/node_modules/isexe/mode.js:8:5\n' +
#11 18.28 gyp verb `which` failed     '    at FSReqCallback.oncomplete (fs.js:169:21)',
#11 18.28 gyp verb `which` failed   code: 'ENOENT'
#11 18.28 gyp verb `which` failed }
#11 18.28 gyp verb check python checking for Python executable "python" in the PATH
#11 18.28 gyp verb `which` failed Error: not found: python
#11 18.28 gyp verb `which` failed     at getNotFoundError (/workspace/node_modules/which/which.js:13:12)
#11 18.28 gyp verb `which` failed     at F (/workspace/node_modules/which/which.js:68:19)
#11 18.28 gyp verb `which` failed     at E (/workspace/node_modules/which/which.js:80:29)
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/which/which.js:89:16
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/isexe/index.js:42:5
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/isexe/mode.js:8:5
#11 18.28 gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:169:21)
#11 18.28 gyp verb `which` failed  python Error: not found: python
#11 18.28 gyp verb `which` failed     at getNotFoundError (/workspace/node_modules/which/which.js:13:12)
#11 18.28 gyp verb `which` failed     at F (/workspace/node_modules/which/which.js:68:19)
#11 18.28 gyp verb `which` failed     at E (/workspace/node_modules/which/which.js:80:29)
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/which/which.js:89:16
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/isexe/index.js:42:5
#11 18.28 gyp verb `which` failed     at /workspace/node_modules/isexe/mode.js:8:5
#11 18.28 gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:169:21) {
#11 18.28 gyp verb `which` failed   stack: 'Error: not found: python\n' +
#11 18.28 gyp verb `which` failed     '    at getNotFoundError (/workspace/node_modules/which/which.js:13:12)\n' +
#11 18.28 gyp verb `which` failed     '    at F (/workspace/node_modules/which/which.js:68:19)\n' +
#11 18.28 gyp verb `which` failed     '    at E (/workspace/node_modules/which/which.js:80:29)\n' +
#11 18.28 gyp verb `which` failed     '    at /workspace/node_modules/which/which.js:89:16\n' +
#11 18.28 gyp verb `which` failed     '    at /workspace/node_modules/isexe/index.js:42:5\n' +
#11 18.28 gyp verb `which` failed     '    at /workspace/node_modules/isexe/mode.js:8:5\n' +
#11 18.28 gyp verb `which` failed     '    at FSReqCallback.oncomplete (fs.js:169:21)',
#11 18.29 gyp verb `which` failed   code: 'ENOENT'
#11 18.29 gyp verb `which` failed }
#11 18.29 gyp ERR! configure error 
#11 18.29 gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
#11 18.29 gyp ERR! stack     at PythonFinder.failNoPython (/workspace/node_modules/node-gyp/lib/configure.js:484:19)
#11 18.29 gyp ERR! stack     at PythonFinder.<anonymous> (/workspace/node_modules/node-gyp/lib/configure.js:406:16)
#11 18.29 gyp ERR! stack     at F (/workspace/node_modules/which/which.js:68:16)
#11 18.29 gyp ERR! stack     at E (/workspace/node_modules/which/which.js:80:29)
#11 18.29 gyp ERR! stack     at /workspace/node_modules/which/which.js:89:16
#11 18.29 gyp ERR! stack     at /workspace/node_modules/isexe/index.js:42:5
#11 18.29 gyp ERR! stack     at /workspace/node_modules/isexe/mode.js:8:5
#11 18.29 gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:169:21)
#11 18.29 gyp ERR! System Linux 5.10.47-linuxkit
#11 18.29 gyp ERR! command "/usr/local/bin/node" "/workspace/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
#11 18.29 gyp ERR! cwd /workspace/node_modules/node-sass
#11 18.29 gyp ERR! node -v v12.10.0
#11 18.29 gyp ERR! node-gyp -v v3.8.0
#11 18.29 gyp ERR! not ok 
#11 18.29 Build failed with error code: 1
#11 18.48 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/chokidar/node_modules/fsevents):
#11 18.48 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm64"})

解決方法

なぜかM1Macで入れたnodeのコンテナにはpython環境とついでにmake環境がないようなので、コマンドで入れてあげればOKです。
最終的に使用したDockerfileは以下のようになっています。

FROM node:12.10-slim

RUN mkdir /workspace
COPY ./package.json /workspace/package.json

RUN apt-get update || : && apt-get install python build-essential -y

WORKDIR /workspace
RUN npm install

ちなみに

Intel入ってる方でも動作確認済みです。

alpine環境の場合

apkコマンドで入れるケースがあったので、その時のコマンドも載せておきます。

apk update && apk add python make gcc g++
9
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
2