48475


commitやwerckerをローカルで実行する際、  
npmコマンドが走り、prettierを使うところでELIFECYCLEのエラーを吐きます。  
疑うべきところが分からず、足掛かりなどでも教えていただけると幸いです。

**環境**

[code]

    $ npm -v
    6.2.0
    $ prettier -v
    1.14.2
    
[/code]

**エラーの詳細**

[code]

    $ sudo git commit -m "wercker.ymlの変更"
    [sudo] akari のパスワード: 
    husky > pre-commit (node v10.7.0)
    
    > wowgit@0.0.1 husky-hooks /home/akari/Desktop/git/wowgit
    > npm run lint && npm test
    
    
    > wowgit@0.0.1 lint /home/akari/Desktop/git/wowgit
    > npm run format && tslint -c tslint.json ./{*,**/*}.{ts,tsx}
    
    
    > wowgit@0.0.1 format /home/akari/Desktop/git/wowgit
    > prettier --list-different "{**/＊,＊}.{js,ts,jsx,tsx,json,graphql}"
    
    .wercker/projects/wowgit-099d3cb5-b990-4503-a377-ed9872e62cb2/client/components/AddRepoModal/AddRepoModal.tsx
    .wercker/projects/wowgit-099d3cb5-b990-4503-a377-ed9872e62cb2/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-1aade1c8-43bd-4aec-9255-6045e9c53fc9/client/components/AddRepoModal/AddRepoModal.tsx
    .wercker/projects/wowgit-1aade1c8-43bd-4aec-9255-6045e9c53fc9/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-2694d784-fe29-464a-911c-e19e3f1f8d0d/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-2694d784-fe29-464a-911c-e19e3f1f8d0d/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-2ebb1a28-26c6-4036-a6cf-81f4e3175684/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-2ebb1a28-26c6-4036-a6cf-81f4e3175684/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-3d591085-bde7-40ba-ad8f-4e0e08a858c7/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-3d591085-bde7-40ba-ad8f-4e0e08a858c7/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-5de420a7-27d7-4b22-aadd-39f5ddb30a32/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-5de420a7-27d7-4b22-aadd-39f5ddb30a32/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-6415c2dc-349d-49da-87f9-4174353f9c58/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-6415c2dc-349d-49da-87f9-4174353f9c58/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-64f5216f-8b28-4051-91cb-c27448fc1682/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-64f5216f-8b28-4051-91cb-c27448fc1682/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-6567be03-c5cd-448c-99e4-37d072a50ffe/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-6567be03-c5cd-448c-99e4-37d072a50ffe/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-6b6e36b5-7f5b-43aa-8802-1a2ad85d3350/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-6b6e36b5-7f5b-43aa-8802-1a2ad85d3350/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-6f642d3d-a248-4043-be2d-9c876d10e6c7/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-6f642d3d-a248-4043-be2d-9c876d10e6c7/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-a8f7e2eb-e296-4f91-994f-a8a38d42c44e/next.config.js
    .wercker/projects/wowgit-a8f7e2eb-e296-4f91-994f-a8a38d42c44e/now.json
    .wercker/projects/wowgit-a8f7e2eb-e296-4f91-994f-a8a38d42c44e/server/index.ts
    .wercker/projects/wowgit-a8f7e2eb-e296-4f91-994f-a8a38d42c44e/server/interfaces/api.ts
    .wercker/projects/wowgit-a8f7e2eb-e296-4f91-994f-a8a38d42c44e/server/interfaces/router.ts
    .wercker/projects/wowgit-a8f7e2eb-e296-4f91-994f-a8a38d42c44e/tsconfig.json
    .wercker/projects/wowgit-a8f7e2eb-e296-4f91-994f-a8a38d42c44e/tslint.json
    .wercker/projects/wowgit-aba9bffc-732d-41a5-b380-e61d0a5cd06e/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-aba9bffc-732d-41a5-b380-e61d0a5cd06e/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-b19fb6a7-9a1d-4273-9210-5eec8ba0ecc1/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-b19fb6a7-9a1d-4273-9210-5eec8ba0ecc1/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-b4e43183-5f0e-47e0-a017-e069fd49518e/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-b4e43183-5f0e-47e0-a017-e069fd49518e/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit-ed7eb603-dc29-4d42-90a0-6c304d0c7119/client/components/AddRepoModal.tsx
    .wercker/projects/wowgit-ed7eb603-dc29-4d42-90a0-6c304d0c7119/client/components/navbarDropdown.tsx
    .wercker/projects/wowgit/client/components/AddRepoModal/AddRepoModal.tsx
    .wercker/projects/wowgit/client/components/navbarDropdown.tsx
    client/components/AddRepoModal/AddRepoModal.tsx
    client/components/navbarDropdown.tsx
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! wowgit@0.0.1 format: ｀prettier --list-different "{**/*,*}.{js,ts,jsx,tsx,json,graphql}"｀
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the wowgit@0.0.1 format 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/akari/.npm/_logs/2018-09-17T01_34_10_348Z-debug.log
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! wowgit@0.0.1 lint: ｀npm run format && tslint -c tslint.json ./{*,**/*}.{ts,tsx}｀
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the wowgit@0.0.1 lint 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/akari/.npm/_logs/2018-09-17T01_34_10_488Z-debug.log
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! wowgit@0.0.1 husky-hooks: ｀npm run lint && npm test｀
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the wowgit@0.0.1 husky-hooks 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/akari/.npm/_logs/2018-09-17T01_34_10_613Z-debug.log
    husky > pre-commit hook failed (add --no-verify to bypass)
    
[/code]

↓ ~/.npm/_logs/2018-09-17T01_34_10_348Z-debug.log

[code]

    0 info it worked if it ends with ok
    1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'format' ]
    2 info using npm@6.2.0
    3 info using node@v10.7.0
    4 verbose run-script [ 'preformat', 'format', 'postformat' ]
    5 info lifecycle wowgit@0.0.1~preformat: wowgit@0.0.1
    6 info lifecycle wowgit@0.0.1~format: wowgit@0.0.1
    7 verbose lifecycle wowgit@0.0.1~format: unsafe-perm in lifecycle true
    8 verbose lifecycle wowgit@0.0.1~format: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/akari/Desktop/git/wowgit/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/akari/Desktop/git/wowgit/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/akari/Desktop/git/wowgit/node_modules/.bin:/home/akari/Desktop/git/wowgit/node_modules/.bin:/home/akari/Desktop/git/node_modules/.bin:/home/akari/Desktop/node_modules/.bin:/home/akari/node_modules/.bin:/home/node_modules/.bin:/node_modules/.bin:/usr/local/bin:/usr/lib/git-core:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
    9 verbose lifecycle wowgit@0.0.1~format: CWD: /home/akari/Desktop/git/wowgit
    10 silly lifecycle wowgit@0.0.1~format: Args: [ '-c',
    10 silly lifecycle   'prettier --list-different "{**/*,*}.{js,ts,jsx,tsx,json,graphql}"' ]
    11 silly lifecycle wowgit@0.0.1~format: Returned: code: 1  signal: null
    12 info lifecycle wowgit@0.0.1~format: Failed to exec format script
    13 verbose stack Error: wowgit@0.0.1 format: `prettier --list-different "{**/*,*}.{js,ts,jsx,tsx,json,graphql}"`
    13 verbose stack Exit status 1
    13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:304:16)
    13 verbose stack     at EventEmitter.emit (events.js:182:13)
    13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
    13 verbose stack     at ChildProcess.emit (events.js:182:13)
    13 verbose stack     at maybeClose (internal/child_process.js:961:16)
    13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
    14 verbose pkgid wowgit@0.0.1
    15 verbose cwd /home/akari/Desktop/git/wowgit
    16 verbose Linux 4.4.0-135-generic
    17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "format"
    18 verbose node v10.7.0
    19 verbose npm  v6.2.0
    20 error code ELIFECYCLE
    21 error errno 1
    22 error wowgit@0.0.1 format: `prettier --list-different "{**/*,*}.{js,ts,jsx,tsx,json,graphql}"`
    22 error Exit status 1
    23 error Failed at the wowgit@0.0.1 format script.
    23 error This is probably not a problem with npm. There is likely additional logging output above.
    24 verbose exit [ 1, true ]
    
[/code]

おそらく、ログファイルの10,11番に書いてあることを疑うべきでしょうが、  
次に何をすると解決できるでしょうか。


CC BY-SA 4.0
2018-09-17T02:37:32.283
48473
2022-03-20T11:23:28.703
2022-03-20T11:23:28.703
3060
30128
question
npm prettier
prettier実行時に発生するELIFECYCLEのエラーを解消したい


> おそらく、ログファイルの10,11番に書いてあることを疑うべきでしょうが

おっしゃる通りです。該当部分からは、以下のコマンドがexit status 1で失敗していることが分かります。

[code]

    prettier --list-different "{**/*,*}.{js,ts,jsx,tsx,json,graphql}"
    
[/code]

この`prettier --list-
different`というコマンドを調べてみましょう。[公式サイト](https://prettier.io/docs/en/cli.html#list-
different)によれば、これは「内容がprettierによって整形されていないファイルの名前を表示する。もしそのようなファイルがあればエラーとなる（＝
exit code 1で終了する）。」というコマンドであることが分かります。

つまり、このコマンドの意図は「ファイルがちゃんとprettierによって整形されているか調べる」ということです。このことから、今回のエラーは、ファイルがprettierによって整形されていなければいけないのに、されていないために発生しているエラーであるということが分かります。

[リポジトリ](https://github.com/superwower/wowgit/blob/master/package.json)を拝見しましたが、`format:fix`というスクリプトがprettierによりファイルを整形するスクリプトのようですね。コミットの前にこれを実行してファイルを整形することでエラーを回避できるでしょう。`husky-
hooks`内で自動的に走るようにするのもよいかと思います。


CC BY-SA 4.0
2018-09-17T05:59:49.370
48475
2018-09-17T05:59:49.370
30079
48473
answer