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

Breaking change in electron-updater 4.3.10 #6000

Closed
davej opened this issue Jun 28, 2021 · 26 comments · Fixed by #6594, #6590 or #6657 · May be fixed by baparham/electron-builder#1
Closed

Breaking change in electron-updater 4.3.10 #6000

davej opened this issue Jun 28, 2021 · 26 comments · Fixed by #6594, #6590 or #6657 · May be fixed by baparham/electron-builder#1

Comments

@davej
Copy link
Contributor

davej commented Jun 28, 2021

  • Version: 4.3.10
  • Electron Version: Effects Electron 11 and before. Does not effect Electron 12 or later.
  • Target: All

Electron-updater has introduced fs/promises which will break the build on Electron 11 and earlier. This is because fs/promises is not supported in Node 12 (which is used by Electron 11). The change was introduced in this PR: #5890

This is a critical issue for anybody on Electron 11 or earlier because it will break their application after an update and it is not possible to recover by pushing a fix in an update.

The best mitigation that I think of here is to publish a 4.3.11 that does not use fs/promises. If you want to use fs/promises then you can publish 5.0.0 that uses fs/promises.

electron-updater

@shownoso
Copy link

I got the same problem

@tub5
Copy link

tub5 commented Jun 28, 2021

This has halted all development on our apps

@theolivenbaum
Copy link

Same here

@sFireFrog
Copy link

。。。I solved this problem by specifying the version in package.json

@tub5
Copy link

tub5 commented Jun 28, 2021

。。。I solved this problem by specifying the version in package.json

That would be a temporary fix.
However, we're using the Electron.NET package which uses a CLI to build our apps. Therefore we can't just change it.
With a breaking change such as this, it shouldn't have been placed as a minor version.

@sFireFrog
Copy link

。。。I solved this problem by specifying the version in package.json

That would be a temporary fix.
However, we're using the Electron.NET package which uses a CLI to build our apps. Therefore we can't just change it.
With a breaking change such as this, it shouldn't have been placed as a minor version.

Yes, I also use Electron.NET, this problem has troubled me for a long time, I directly modified the CLI

@tub5
Copy link

tub5 commented Jun 28, 2021

。。。I solved this problem by specifying the version in package.json

That would be a temporary fix.
However, we're using the Electron.NET package which uses a CLI to build our apps. Therefore we can't just change it.
With a breaking change such as this, it shouldn't have been placed as a minor version.

Yes, I also use Electron.NET, this problem has troubled me for a long time, I directly modified the CLI

Nice. I have put a PR in to upgrade us to Electron 12.0.12 and Tweeted Gregor. No PR's since Jan makes for a sad dev team.

@davej
Copy link
Contributor Author

davej commented Jun 28, 2021

I solved this problem by specifying the version in package.json

Most electron builder users won't be aware of this issue before they publish a new release of their app. For this reason, it's best to fix this in a patch release.

@ekuchynski
Copy link

ekuchynski commented Jun 28, 2021

Also got this surprise today. Built and deployed updates refused to start on many user machines.. :( Please help. We use Electron .NET as well.

@theolivenbaum
Copy link

@davej: I'm publishing a temp nuget package with the fixes your PR (and including also the fix for the splashscreen that has been long pending). It's based on my fork here: https://github.com/theolivenbaum/Electron.NET

If you want to use it, you'll need to:

As this is now using Electron12, you also need to add this to your CreateWindow calls:

Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
{
   // ...
    WebPreferences = new WebPreferences()
    {
        NodeIntegration = true,
        ContextIsolation = false
    },
   // ...

We're using this one till it's fixed upstream, and testing if everything still works. If you want to use it for now and hit anything, drop me an email to rafael (at) curiosity (dot) ai

@skelt
Copy link

skelt commented Jun 28, 2021

we need to use nodejs 12 for windows server 2003. is there a solution that works with nodejs12?

@davej
Copy link
Contributor Author

davej commented Jun 28, 2021

@develar @mmaietta I usually don't like to tag core devs but I think this is particularly nasty given that there isn't a way to recover once a problematic version has been shipped (apart from emailing affected end-users to download again).

@develar
Copy link
Member

develar commented Jun 28, 2021

4.3.9 is marked as latest again for now.

4.3.10 was marked as a next for a two months.

@mankeheaven
Copy link

hello, which version can I rollback to differential download?
link #5948
Is there anyway to differential download lower than 4.3.9, other than fork this resp?

@skelt
Copy link

skelt commented Jun 29, 2021

electronize build works using nodejs14 and with 4.3.9 set to the latest we're up and running again on win server 2003

@tub5
Copy link

tub5 commented Jun 29, 2021

@davej: I'm publishing a temp nuget package with the fixes your PR (and including also the fix for the splashscreen that has been long pending). It's based on my fork here: https://github.com/theolivenbaum/Electron.NET

If you want to use it, you'll need to:

As this is now using Electron12, you also need to add this to your CreateWindow calls:

Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
{
   // ...
    WebPreferences = new WebPreferences()
    {
        NodeIntegration = true,
        ContextIsolation = false
    },
   // ...

We're using this one till it's fixed upstream, and testing if everything still works. If you want to use it for now and hit anything, drop me an email to rafael (at) curiosity (dot) ai

Cheers for that.
Gregor is reviewing the PR's Thursday evening so hopefully we'll have an update shortly after.

@Mgonand
Copy link
Contributor

Mgonand commented Jun 29, 2021

For a quick workaround, you can patch (using patch-package npm if you want to persist through commits) the AppUpdater.js file (located in node_modules/electron-updater/out/AppUpdater.js):

diff --git a/node_modules/electron-updater/out/AppUpdater.js b/node_modules/electron-updater/out/AppUpdater.js
index 42ed9a3..469fa39 100644
--- a/node_modules/electron-updater/out/AppUpdater.js
+++ b/node_modules/electron-updater/out/AppUpdater.js
@@ -5,7 +5,6 @@ const builder_util_runtime_1 = require("builder-util-runtime");
 const crypto_1 = require("crypto");
 const events_1 = require("events");
 const fs_extra_1 = require("fs-extra");
-const promises_1 = require("fs/promises");
 const js_yaml_1 = require("js-yaml");
 const lazy_val_1 = require("lazy-val");
 const path = require("path");
@@ -377,7 +376,7 @@ class AppUpdater extends events_1.EventEmitter {
         if (this._appUpdateConfigPath == null) {
             this._appUpdateConfigPath = this.app.appUpdateConfigPath;
         }
-        return js_yaml_1.load(await promises_1.readFile(this._appUpdateConfigPath, "utf-8"));
+        return js_yaml_1.load(await fs_extra_1.readFile(this._appUpdateConfigPath, "utf-8"));
     }
     computeRequestHeaders(provider) {
         const fileExtraDownloadHeaders = provider.fileExtraDownloadHeaders;
@@ -395,7 +394,7 @@ class AppUpdater extends events_1.EventEmitter {
     async getOrCreateStagingUserId() {
         const file = path.join(this.app.userDataPath, ".updaterId");
         try {
-            const id = await promises_1.readFile(file, "utf-8");
+            const id = await fs_extra_1.readFile(file, "utf-8");
             if (builder_util_runtime_1.UUID.check(id)) {
                 return id;
             }
@@ -477,7 +476,7 @@ class AppUpdater extends events_1.EventEmitter {
         }
         const downloadedUpdateHelper = await this.getOrCreateDownloadHelper();
         const cacheDir = downloadedUpdateHelper.cacheDirForPendingUpdate;
-        await promises_1.mkdir(cacheDir, { recursive: true });
+        await fs_extra_1.mkdir(cacheDir, { recursive: true });
         const updateFileName = getCacheUpdateFileName();
         let updateFile = path.join(cacheDir, updateFileName);
         const packageFile = packageInfo == null ? null : path.join(cacheDir, `package-${version}${path.extname(packageInfo.path) || ".7z"}`);
@@ -499,14 +498,14 @@ class AppUpdater extends events_1.EventEmitter {
             await downloadedUpdateHelper.clear().catch(() => {
                 // ignore
             });
-            return await promises_1.unlink(updateFile).catch(() => {
+            return await fs_extra_1.unlink(updateFile).catch(() => {
                 // ignore
             });
         };
         const tempUpdateFile = await DownloadedUpdateHelper_1.createTempUpdateFile(`temp-${updateFileName}`, cacheDir, log);
         try {
             await taskOptions.task(tempUpdateFile, downloadOptions, packageFile, removeFileIfAny);
-            await promises_1.rename(tempUpdateFile, updateFile);
+            await fs_extra_1.rename(tempUpdateFile, updateFile);
         }
         catch (e) {
             await removeFileIfAny();

This worked for me. Hope it helps.

@davej
Copy link
Contributor Author

davej commented Jun 29, 2021

Thanks, @Mgonand. You can probably also just do a 1-line diff.

-const promises_1 = require("fs/promises");
+const promises_1 = require("fs").promises;

@Mgonand
Copy link
Contributor

Mgonand commented Jun 29, 2021

You're right, that's better. I did the patch quick and didn't realize it. Thanks.

@axetroy
Copy link

axetroy commented Jul 22, 2021

fs/promises are great, but it breaking up electron version locking.

we need to upgrade the old version to electrion@^13

@stale
Copy link

stale bot commented Sep 21, 2021

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Sep 21, 2021
@stale stale bot closed this as completed Oct 2, 2021
@toschlog
Copy link

Yes, I think this issue is still relevant.

I'm using electron-updater 4.3.9. Differential downloads don't work. Apparently they're fixed in 4.3.10, but that version won't work in Electron 10, which I have to use.

I'm going to try the patch-package thing but it would be good to release a 4.3.11 that fixes the breaking change in 4.3.10.

@mmaietta
Copy link
Collaborator

mmaietta commented Jan 28, 2022

If I'm understanding this correctly, it seems we need to support node 14 (electron 12) and node 12 (electron 10). I wonder if we could use something like this for importing? Not at my dev machine to check

let fsPromises
try {
   fsPromises = require('fs/promises')
} catch (e} {
   fsPromises = require('fs').promises
}

@toschlog
Copy link

@mmaietta I ran your try/catch code and it worked fine. Seems a good solution.

@mmaietta mmaietta reopened this Jan 30, 2022
@stale stale bot removed the backlog label Jan 30, 2022
mmaietta added a commit to mmaietta/electron-builder that referenced this issue Jan 30, 2022
…ctron that use node 12 and below.

Fixes: electron-userland#6000

Regenerating docs addition from PR electron-userland#6585
@mmaietta
Copy link
Collaborator

I noticed that fs-extra is already being used and the API's overlap, can someone try replacing this one import line to just swap in fs-extra like so?

const fs_extra_1 = require("fs-extra");
const promises_1 = fs_extra_1;

I'm working on getting this issue resolved so that you all are able to update your electron-updater to the newest alpha v5.

mmaietta added a commit that referenced this issue Jan 31, 2022
* Replacing fs/promises with fs-extra to support legacy versions of electron that use node 12 and below.
Fixes: #6000
@mmaietta
Copy link
Collaborator

Migrated commands to use fs-extra and released this in electron-updater@5.0.0-alpha.3 (note: alpha)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment