npmのエラーって、ログ見ても全然ピンと来ないので本当に嫌い・・・
npm系のエラーはだいたい
$ rm -rf node_modules
$ rm package-lock.json
$ npm cache clear --force
これらを実行した後に、
$ npm i
$ npm run dev
などやると直ることが多いんだけど今回はそれでも直らず、、、おもむろに仮想マシンを再起動してビルドし直したら無事に通りました。
理由は全くわかりません。
(仮想マシンじゃなくmac本体で開発してる場合も、mac再起動したら直るかもね。)
とはいえ直ったので、次にまた困った時用のメモって感じで。あと、この方法はググっても出てこなかったのでいつか誰かに助けになればと思って。
以下、今回の詳しい状況。
開発環境
macos上にvagrantで立てた仮想マシン(amazon linux 2018.3)
エラーが起きた状況
別メンバーが作業中のブランチに切り替えて、
$ npm i
$ npm run dev
を実行した際にエラー発生。なお、別メンバーの環境上では問題なく動いていた。
エラーログ
$ npm run dev 実行時ログ
$ npm run dev > n@1.0.0 dev /var/www/cenq > node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js 66% building 841/889 modules 48 active /var/www/cenq/node_modules/entities/index.jsnpm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! n@1.0.0 dev: `node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the n@1.0.0 dev 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! /home/vagrant/.npm/_logs/2020-01-14T07_56_29_229Z-debug.log
/home/vagrant/.npm/_logs/2020-01-14T07_56_29_229Z-debug.log
0 info it worked if it ends with ok 1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'dev' ] 2 info using npm@6.13.4 3 info using node@v10.18.0 4 verbose run-script [ 'predev', 'dev', 'postdev' ] 5 info lifecycle n@1.0.0~predev: n@1.0.0 6 info lifecycle n@1.0.0~dev: n@1.0.0 7 verbose lifecycle n@1.0.0~dev: unsafe-perm in lifecycle true 8 verbose lifecycle n@1.0.0~dev: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/var/www/cenq/node_modules/.bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/vagrant/.local/bin:/home/vagrant/bin 9 verbose lifecycle n@1.0.0~dev: CWD: /var/www/cenq 10 silly lifecycle n@1.0.0~dev: Args: [ '-c', 10 silly lifecycle 'node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js' ] 11 silly lifecycle n@1.0.0~dev: Returned: code: 1 signal: null 12 info lifecycle n@1.0.0~dev: Failed to exec dev script 13 verbose stack Error: n@1.0.0 dev: `node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js` 13 verbose stack Exit status 1 13 verbose stack at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16) 13 verbose stack at EventEmitter.emit (events.js:198:13) 13 verbose stack at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14) 13 verbose stack at ChildProcess.emit (events.js:198:13) 13 verbose stack at maybeClose (internal/child_process.js:982:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5) 14 verbose pkgid n@1.0.0 15 verbose cwd /var/www/cenq 16 verbose Linux 4.14.154-99.181.amzn1.x86_64 17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "dev" 18 verbose node v10.18.0 19 verbose npm v6.13.4 20 error code ELIFECYCLE 21 error errno 1 22 error n@1.0.0 dev: `node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js` 22 error Exit status 1 23 error Failed at the n@1.0.0 dev script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 1, true ]