electron:'^20.0.2'
dotenv:'^16.0.3'
electron-builder"^23.3.3"
폴더 root 최상단에 .env를 생성해서 KEY값을 입력해도 electron node와 BrowserWindow에선 process.env.API_KEY가 undefined로 나타난다.
yarn add dotenv
main.ts
import "dotenv/config"
적용후
정상적으로 작동한다.
하지만 BrowserWindow에선 process.env.API_KEY를 호출했더니 process is not defined 오류가 발생했다.
main.ts
const mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
})
webPreferences옵션에 nodeIntegration 는 ture, contextIsolation는 false를 해주면 해결된다.
contextIsolation 설정을 끄면 아래에 오류가 생긴다.
main process에서 contextBridge 함수 호출을 전부 지워주면 해결된다.