nodejsのアップデートでハマった
概要
nodejsのアップデートとエラーの対応の方法について
nodejsのアップデート
1.指定のバージョンのダウンロード
distributions/README.md at master · nodesource/distributions · GitHub
curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -
2.古いバージョンの削除
rm /etc/yum.repos.d/nodesource-el.repo
3.yumのセットアップ
yum clean all
※これをやらないと、インストール時に旧バージョンを見に行って失敗する
4.nodejsの削除
yum remove nodejs
5.nodejsの再インストール
yum install nodejs
yarnの更新
1.yarnの削除
yum remove yarn
2.yarnのインストール
yum install yarn
webpackerの更新
1.webpackerのアップデート(gem)
bundle update webpacker
2.webpackerのアップデート(node_modules)
yarn upgrade @rails/webpacker --latest
3.webpack-dev-serverのアップデート
yarn upgrade webpack-dev-server --latest
トラブルシューティング
1.nodejsのアップデート
yum clean all
これを知らずに、いつまでもnodejsが更新できないという事に...
2.nodejsのアップデートやると、凄まじい数のエラーが出ることがある
yarn install v1.22.5 warning package.json: No license field warning No license field [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.4: The platform "linux" is incompatible with this module. info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... warning "@rails/webpacker > postcss-cssnext@3.1.0" has unmet peer dependency "caniuse-lite@^1.0.30000697". warning " > webpack-dev-server@2.11.2" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0". warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0". [4/4] Building fresh packages... [-/2] ⢀ waiting... error /to/app/path/node_modules/node-sass: Command failed. Exit code: 1 Command: node scripts/build.js ... ... ... In file included from ../src/binding.cpp:1:0: ../../nan/nan.h: In instantiation of ‘void Nan::imp::SetMethodAux(T, v8::Local<v8::String>, v8::Local<v8::FunctionTemplate>, ...) [with T = v8::Local<v8::Object>]’: ../../nan/nan.h:2353:57: required from ‘void Nan::SetMethod(HandleType<T>, const char*, Nan::FunctionCallback) [with T = v8::Object; HandleType = v8::Local; Nan::FunctionCallback = void (*)(const Nan::FunctionCallbackInfo<v8::Value>&)]’ ../src/binding.cpp:351:42: required from here ../../nan/nan.h:2337:3: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated (declared at /home/user_name/.node-gyp/12.18.4/include/node/v8.h:3498): Use maybe version [-Wdeprecated-declarations] recv->Set(name, GetFunction(tpl).ToLocalChecked()); ^ make: *** [Release/obj.target/binding/src/binding.o] エラー 1 make: ディレクトリ `/to/app/path/node_modules/node-sass/build' から出ます gyp ERR! build error gyp ERR! stack Error: `make` failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/to/app/path/node_modules/node-gyp/lib/build.js:262:23) gyp ERR! stack at ChildProcess.emit (events.js:315:20) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) gyp ERR! System Linux 4.14.33-51.37.amzn1.x86_64 gyp ERR! command "/usr/bin/node" "/to/app/path/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd /to/app/path/node_modules/node-sass gyp ERR! node -v v12.18.4 gyp ERR! node-gyp -v v3.7.0 gyp ERR! not ok Build failed with error code: 1
こういうときは
yarn why node-sass
を使うと、何に依存してるかとかが分かるので、これを元にアタリをつけると良い。
yarn why v1.22.5 warning package.json: No license field [1/4] Why do we have the module "node-sass"...? [2/4] Initialising dependency graph... warning No license field [3/4] Finding dependency... [4/4] Calculating file sizes... => Found "node-sass@4.9.2" info Reasons this module exists - "@rails#webpacker" depends on it - Hoisted from "@rails#webpacker#node-sass" info Disk size without dependencies: "11.64MB" info Disk size with unique dependencies: "16.41MB" info Disk size with transitive dependencies: "11.64MB" info Number of shared dependencies: 115 Done in 1.67s.