npm install コマンドでエラーが出たときの対処法

未分類

npm install コマンドでエラーが出たときの対処法

起きた事象

sqlite3をnpmでインストールしようとしたら、以下のようなエラーが出てしまった。

$ npm install sqlite3

(以下、コマンド実行後に表示されたエラー内容)
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported

> sqlite3@5.0.1 install /Users/username/Desktop/passSystem/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download 
node-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v5.0.1/napi-v6-darwin-x64.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for sqlite3@5.0.1 and node@14.8.0 (node-v83 ABI, unknown) (falling back to source compile with node-gyp) 
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.

gyp: No Xcode or CLT version detected!
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/Users/username/.nodebrew/node/v14.8.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Darwin 19.6.0
gyp ERR! command "/Users/username/.nodebrew/node/v14.8.0/bin/node" "/Users/username/.nodebrew/node/v14.8.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/username/Desktop/passSystem/node_modules/sqlite3/lib/binding/napi-v6-darwin-x64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/Users/username/Desktop/passSystem/node_modules/sqlite3/lib/binding/napi-v6-darwin-x64" "--napi_version=6" "--node_abi_napi=napi" "--napi_build_version=6" "--node_napi_label=napi-v6"
gyp ERR! cwd /Users/username/Desktop/passSystem/node_modules/sqlite3
gyp ERR! node -v v14.8.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/Users/username/.nodebrew/node/v14.8.0/bin/node /Users/username/.nodebrew/node/v14.8.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/username/Desktop/passSystem/node_modules/sqlite3/lib/binding/napi-v6-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/username/Desktop/passSystem/node_modules/sqlite3/lib/binding/napi-v6-darwin-x64 --napi_version=6 --node_abi_napi=napi --napi_build_version=6 --node_napi_label=napi-v6' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/username/Desktop/passSystem/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1051:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
node-pre-gyp ERR! System Darwin 19.6.0
node-pre-gyp ERR! command "/Users/username/.nodebrew/node/v14.8.0/bin/node" "/Users/username/Desktop/passSystem/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/username/Desktop/passSystem/node_modules/sqlite3
node-pre-gyp ERR! node -v v14.8.0
node-pre-gyp ERR! node-pre-gyp -v v0.11.0
node-pre-gyp ERR! not ok 
Failed to execute '/Users/username/.nodebrew/node/v14.8.0/bin/node /Users/username/.nodebrew/node/v14.8.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/username/Desktop/passSystem/node_modules/sqlite3/lib/binding/napi-v6-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/username/Desktop/passSystem/node_modules/sqlite3/lib/binding/napi-v6-darwin-x64 --napi_version=6 --node_abi_napi=napi --napi_build_version=6 --node_napi_label=napi-v6' (1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sqlite3@5.0.1 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the sqlite3@5.0.1 install 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!     /Users/username/.npm/_logs/2021-02-06T02_04_36_107Z-debug.log

エラーの原因

注目すべきは、ここ

gyp: No Xcode or CLT version detected!

どうやら、XcodeまたはCLTのバージョンが検出されなかったみたい。

解決策

とりあえず、以下のコマンドを入力したら、npm install ができるようになりました。

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install

Xcode Command Line Tools を、アンインストール、インストールするコマンドです。

参考

コメント

タイトルとURLをコピーしました