Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electron-updater: Named export 'autoUpdater' not found #7976

Closed
ashwin-mittal opened this issue Jan 11, 2024 · 3 comments
Closed

electron-updater: Named export 'autoUpdater' not found #7976

ashwin-mittal opened this issue Jan 11, 2024 · 3 comments

Comments

@ashwin-mittal
Copy link

  • Node Version: 18.18.2
  • Electron Version: 28.0.0
  • Electron Type (current, beta, nightly): current
    Which version of electron-updater are you using (if applicable)? 6.1.1

I am not able to static import (import { autoUpdater } from "electron-updater" ) electron-updater in my electron application where it is mentioned clearly in the docs that we can do that. Here is the repository to reproduce the issue.

@mmaietta
Copy link
Collaborator

mmaietta commented Jan 24, 2024

In the console logs, there's an error as to why it doesn't work (due to package.json "type": "module") in addition to how to properly import a CJS module.

App threw an error during load
file:///Users/michael.maietta/Development/electron-updater-issue-main/index.js:1
import { autoUpdater } from "electron-updater";
         ^^^^^^^^^^^
SyntaxError: Named export 'autoUpdater' not found. The requested module 'electron-updater' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using

import pkg from 'electron-updater';
const { autoUpdater } = pkg;

Solution:

import pkg from 'electron-updater';
const { autoUpdater } = pkg;

@undergroundwires
Copy link

Any plans to support ESM natively in electron-updater?

Thank you for the post @mmaietta, it solves the problem but I believe it is a workaround rather than an actual solution. If this is the way forward, I believe the docs should be updated.

undergroundwires added a commit to undergroundwires/privacy.sexy that referenced this issue Mar 18, 2024
This commit bumps Electron and related dependencies to their latest
versions to leverage native ESM support. It adjusts build configuration
to use native ESM support instead of relying on CommonJS bundling.

Key changes:

- Bump Electron to latest v29.
  Electron v28 ships with native ESM/ECMAScript modules support.
  Details on Electron ESM support:
    - electron/electron#21457
    - electron/electron#37535
- Bump `electron-builder` to latest v24.13.
  `electron-builder` is used to package and publish the application.
  It supports ESM since 24.10.
  Details on `electron-builder` ESM support:
    - electron-userland/electron-builder#7936
    - electron-userland/electron-builder#7935
- Bump `electron-log` to latest v5.1.
  `electron-log` supports ESM since version 5.0.4.
  Details on `electron-log` ESM support:
    - megahertz/electron-log#390.
- Change `electron-vite` configuration to bundle as ESM instead of
  CommonJS to leverage Electron's native ESM support.

Other supporting changes:

- Add type hint for electron-builder configuration file.
- Update import statements for `electron-updater` as it still is a
  CommonJS module and does not support ESM.
  Details:
    - electron-userland/electron-builder#7976
- Improve `electron-builder` configuration file to dynamically locate
  main entry files, supporting various JavaScript file extensions
  (`.js`, `.mjs` and `.cjs`) to facilitate easier future changes.
- Change comment about Electron process-specific module alias
  registration. This issue has been fixed in `electron-vite`, but
  subpath module imports for Electron still do not work when building
  tests (`npm run test:unit`).
  Details:
   - alex8088/electron-vite#372
- Add `electron-log` in bundling process instead of externalizing to
  workaround Electron ESM loader issues with subpath imports (inability
  to do `electron-log/main`).
  Details:
    - alex8088/electron-vite#401
    - electron/electron#41241
- Improve desktop runtime error checks' assertion message for better
  clarity.
@mmaietta
Copy link
Collaborator

It's probably unlikely I think in order to maintain backward support? I think electron-builder could be a hybrid npm package but that looks to require significant changes in both compilation, package imports, and test runners due to the monorepo configuration

Great feedback on the docs, I'll add that to my (lengthy) todo list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants