9
4

More than 3 years have passed since last update.

2021年、gulp-sassをインストールしようとして躓いた

Posted at

この度完全新規のコーディング案件に携わることになったため、久しぶりに1年前まで使用していたpackage.jsonを引っ張りだしnpm intall を実行したところ、gulp-sassのインストールでエラーを吐いてしまい躓きました。
3時間調査したり悩んだりした結果、解決しましたので備忘録として残します。

エラー状況

Windows10環境で npm install gulp-sass --save-dev すると、下記の通りログが出力され、インストールできない。
私のPCにはNode.jsの【最新版(v15.5.0)】がインストールされておりました。

エラーのログ

cmd
PS G:\data\html> npm install gulp-sass --save-dev
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.

> node-sass@4.14.1 install G:\data\html\node_modules\gulp-sass\node_modules\node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/win32-x64-88_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.14.1/win32-x64-88_binding.node": 

HTTP error 404 Not Found

Hint: If github.com is not accessible in your location
      try setting a proxy via HTTP_PROXY, e.g.

      export HTTP_PROXY=http://example.com:1234

or configure npm proxy via

      npm config set proxy http://example.com:8080

> node-sass@4.14.1 postinstall G:\data\html\node_modules\gulp-sass\node_modules\node-sass 
> node scripts/build.js

Building: C:\Program Files\nodejs\node.exe G:\data\html\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   'C:\\Program Files\\nodejs\\node.exe',
gyp verb cli   'G:\\data\\html\\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.5.0 | win32 | x64
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 (G:\data\html\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (G:\data\html\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (G:\data\html\node_modules\which\which.js:80:29)
gyp verb `which` failed     at G:\data\html\node_modules\which\which.js:89:16
gyp verb `which` failed     at G:\data\html\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at G:\data\html\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:199:21)
gyp verb `which` failed  python2 Error: not found: python2
gyp verb `which` failed     at getNotFoundError (G:\data\html\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (G:\data\html\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (G:\data\html\node_modules\which\which.js:80:29)
gyp verb `which` failed     at G:\data\html\node_modules\which\which.js:89:16
gyp verb `which` failed     at G:\data\html\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at G:\data\html\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:199: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` succeeded python C:\Documents and Settings\●●●\AppData\Local\Programs\Python\Python39\python.EXE
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: C:\Documents and Settings\●●●\AppData\Local\Programs\Python\Python39\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                       ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (node:child_process:333:12)
gyp ERR! stack     at ChildProcess.emit (node:events:376:20)
gyp ERR! stack     at maybeClose (node:internal/child_process:1063:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:295:5)
gyp ERR! System Windows_NT 10.0.19042
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "G:\\data\\html\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd G:\data\html\node_modules\gulp-sass\node_modules\node-sass
gyp ERR! node -v v15.5.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN GulpTask@1.0.0 No description
npm WARN GulpTask@1.0.0 No repository field.
npm ERR! node-sass@4.14.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.14.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Documents and Settings\●●●\AppData\Roaming\npm-cache\_logs\2021-01-20T16_23_09_981Z-debug.log 

debug.logを確認すると同じエラーが出力されておりました。
Pythonが必要そうなログが出ているのでインストールしたり、npmのキャッシュを消して再インストールし直したり…
検索して出てきたものを片っ端から試しましたが直りません。
なんとなく、「どうもnode-sassが悪いっぽい」ということだけ情報を掴みました。

解決策

Node.jsのバージョンを【推奨版】にダウングレードしました。
(Node.jsをアンインストール → 公式サイトから左側の「推奨版」をダウンロード&インストール)
node.png

これだけで無事gulp-sassをインストールすることができました。

原因

なぜダウングレードするだけで解決したのか?
原因はgulp-sass内で使用しているnode-sassにありました。

  • node-sassの最新バージョンはv5.0.0(これはNode.js v15.x に対応しています)
  • gulp-sass(v3.2.1)で使用しているnode-sassはv4.14.1。これはNode.js v14.x までしか対応していません

node-sassがどのNode.jsのバージョンに対応しているか?はGithubのReleaseを開くと確認できます。
https://github.com/sass/node-sass/releases
nodesass.png

バージョンに注意!

今まで「最新こそ正義」と思い最新版を入れてきましたが、こんな落とし穴があるとは思いませんでした。
どのソフトなどを使用していてもそうですが、自分が使うパッケージに合わせてインストールするバージョンを選ぶか、使うパッケージが最新版に追いついていないのであれば代替のものを探すことが大事ですね。

9
4
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
4