Electron 문제 해결 모음

2022년 1월 2일 수정

≡ 목차 (Table of Contents)

이 글은 Electron을 이용해 앱을 개발하는 과정에서 겪은 에러 등을 해결해가는 삽질 과정에서 얻은 결론을 간단하게 정리한다.

require is not defined

Uncaught ReferenceError: require is not defined

이 오류는 아래와 같이 webPreferences 설정에서 nodeIntegrationcontextIsolation 두 가지 설정을 추가하여 해결이 가능하다.

window = new BrowserWindow({
    ...
    webPreferences: {
        ...
        nodeIntegration: true,
        contextIsolation: false,
        ...
    }
});

사실 둘 다 보안에 영향을 주는 설정이긴 한데 이게 없으면 상당수의 앱은 개발이 불가능할지도 모를 정도로 대중적인 설정이기도 하다.