After updating node-fetch
to v3, the following JavaScript error message appears when trying to launch my Electron app:
Uncaught Exception: Error [ERR_REQUIRE_ESM]: require() of ES Module (…) not supported. Instead change the required … to a dynamic import() …
I have found here that I should replace
JavaScript
x
2
1
const fs = require('fs');
2
with:
JavaScript
1
2
1
import fs from "fs";
2
But how to replace in the same fashion the following?
JavaScript
1
7
1
// Modules to control application life and create native browser window
2
const {
3
app,
4
session,
5
BrowserWindow
6
} = require('electron');
7
Advertisement
Answer
Typically, you would do this as you have done it with fs
and would do with other ES modules:
JavaScript
1
2
1
import { app, session, BrowserWindow } from "electron";
2
However, I don’t believe you can do this directly with Electron as it’s a CommonJS module and not all the modules are directly named as exports.
You should be able to import what you need via the default import however:
JavaScript
1
3
1
import electron from "electron";
2
const { app, session, BrowserWindow } = electron;
3