본문 바로가기
프로젝트/node.js

[프로젝트] puppeteer 사용 오류 해결

by 왕자두 2023. 6. 17.

현재 참여 중인 프로젝트에서 크롤링을 위해 puppeteer 모듈을 사용하는데 공용 서버에 크롤링 기능까지 구현 후 올려뒀는데 프론트 쪽에서 서버 에러가 난 것 같다는 연락을 받고 pm2 로그를 찍어 오류 내용을 확인해봤다.

pm2 logs

그랬더니 ..

/home/ubuntu/.pm2/logs/app-error.log last 15 lines:
0|app      |     In the near feature `headless: true` will default to the new Headless mode
0|app      |     for Chrome instead of the old Headless implementation. For more
0|app      |     information, please see https://developer.chrome.com/articles/new-headless/.
0|app      |     Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
0|app      |     If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.
0|app      |
0|app      | Error during crawling: Error: Could not find Chrome (ver. 113.0.5672.63). This can occur if either
0|app      |  1. you did not perform an installation before running the script (e.g. `npm install`) or
0|app      |  2. your cache path is incorrectly configured (which is: /home/ubuntu/.cache/puppeteer).

이러한 에러들이 나있었다. 대충 읽어보니 npm install 을 다시 하라는 것 같은데 이미 puppeteer 모듈은 npm install로 설치를 했었어서 구글링을 해봤다. node_modules에 직접 접근해서 내부에 있는 puppeteer 모듈 안에서 npm install을 실행하라고 하길래 해봤다.

npm install

그리고 나서 postman으로 테스트 해봤더니 여전히 안됐다. 도대체 뭐지?! 다시 로그를 찍어봤더니 에러 내용이 조금 달라졌다.

0|app      | Error during crawling: Error: Failed to launch the browser process!
0|app      | /home/ubuntu/.cache/puppeteer/chrome/linux-113.0.5672.63/chrome-linux64/chrome: error while loading shared libraries: libgbm.so.1: cannot open shared object file: No such file or directory

해당 내용으로 다시 구글링 해보니  puppeteer 버전 때문에 생긴 오류인 것 같았다! puppeteer@3.0.0을 사용하려면 추가적인 라이브러리가 필요하여 libgdm-dev(GBM 버퍼 관리 라이브러리 - 그래픽 랜더링을위한 버퍼 할당 메커니즘 제공)를 추가적으로 설치해주었다.

sudo apt-get update
sudo apt-get install -y libgbm-dev

 그랬더니 문제 해결!

 

참고

https://stackoverflow.com/questions/68051648/could-not-find-expected-browser-chrome-locally

 

Could not find expected browser chrome locally

This Meteor code uses "puppeteer 8.0.0", "puppeteer-core 10.0.0", puppeteer-extra 3.1.18" and "puppeteer-extra-plugin-stealth 2.7.8", It gives this error: Error:...

stackoverflow.com

https://github.com/actions/runner-images/issues/732

 

puppeteer can't launch chromium, missing shared library libgbm.so · Issue #732 · actions/runner-images

Describe the bug My build actions involve running puppeteer tests with chromium. Today (April 16th, 2020) I started to get the following message: Starting Chrome Headless /opt/hostedtoolcache/Pytho...

github.com