앙큼한 개발기록

[electron] serialport node-gyp error 오류 본문

개발/electron

[electron] serialport node-gyp error 오류

angkeum 2022. 7. 26. 10:16

electron을 사용하면서 serialport 를 연결하려고 하니 node-gyp 오류가 나오고 

연결도 안되고

리빌드도 안되고 별짓을 다 해봤지만 

 

결과적으로 electron-nuxt를 사용하면서 npm이 아닌 yarn을 사용하면서 발생한 패키지 설정 오류였다. 

 

나에게 발생한 오류는 다음과 같았다. 

 Cannot find module 'C:\usr\local\lib\node_modules\node-gyp\bin\node-gyp.js'

 

해당 오류 발생시 C드라이브에 있는 node-module이 어디 있는지 찾아서 

해당 모듈로 path를 재 설정 해주니 해결 되었다. 

 

우선 powerShell이나 관리자 cmd를 열어서 

npm config list
// or
yarn config list

로 config setting 값을 확인 하고 

 

npm config delete node-gyp
// or
yarn config delete node-gyp

로 node-gyp 연결 값을 삭제하고 

npm config set node_gyp <path>

// or

yarn config set node_gyp <path>

로 설정

 

참고 

https://classic.yarnpkg.com/en/docs/cli/config

 

 

 

serialport 에서 index.js를 못찾거나 module를 못찾는 경우 

serialport version을 잘 확인해 봐야 된다. 

 

내 경우에는 9.x.x -> 10.x.x로 변경하고 

코드 수정하고 해결 되었다. 

버전 업그레이드는 "^9.x.x"로 되어 있는 경우 매인 버전은 업그레이드가 되지 않기 때문에 

그냥 삭제하고 다시 설치 해야 된다. 

 

버전 업데이트 대응에 관해서는 아래 url 참고 

https://serialport.io/docs/guide-upgrade#upgrading-from-9x-to-10x

Comments