npm runを実行したら Cannot find module 'npmlog' と言われた
$ npm run hogefuga
みたいなことをやろうとしたらエラーが出てきました。単純に $ npm
を実行しようとしても同じエラーが出るようでした。
$ npm module.js:559 throw err; ^ Error: Cannot find module 'npmlog' at Function.Module._resolveFilename (module.js:557:15) at Function.Module._load (module.js:484:25) at Module.require (module.js:606:17) at require (internal/module.js:11:18) at /usr/local/lib/node_modules/npm/bin/npm-cli.js:22:13 at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:92:3) at Module._compile (module.js:662:30) at Object.Module._extensions..js (module.js:673:10) at Module.load (module.js:575:32) at tryModuleLoad (module.js:515:12)
nodeについてはnodebrewで管理しています。今日はv9.8.0にバージョンアップしたところです。
あちこちネットで調べた結果、以下の方法で落ち着きました。 nodebrewを使っているので、シンボリックリンクを貼りました。
$ sudo rm -rf /usr/local/lib/node_modules $ sudo ln -s /Users/mymac/.nodebrew/current/lib/node_modules /usr/local/lib/node_modules
とりあえずこれで解決して、npmを叩いて正常に動作することを確認できました。
$ npm Usage: npm <command> where <command> is one of: access, adduser, bin, bugs, c, cache, completion, config, ddp, dedupe, deprecate, dist-tag, docs, doctor, edit, explore, get, help, help-search, i, init, install, install-test, it, link, list, ln, login, logout, ls, outdated, owner, pack, ping, prefix, profile, prune, publish, rb, rebuild, repo, restart, root, run, run-script, s, se, search, set, shrinkwrap, star, stars, start, stop, t, team, test, token, tst, un, uninstall, unpublish, unstar, up, update, v, version, view, whoami npm <command> -h quick help on <command> npm -l display full usage info npm help <term> search for help on <term> npm help npm involved overview Specify configs in the ini-formatted file: /Users/mymac/.npmrc or on the command line via: npm <command> --key value Config info can be viewed via: npm help config npm@5.6.0 /Users/mymac/.nodebrew/node/v9.8.0/lib/node_modules/npm
金曜日に地味なハマりをしましたが、とりあえずひと安心ですね。