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

Building NSIS installers broken after switching from 22.10.5 to 22.11.1 #5863

Closed
ezzatron opened this issue May 6, 2021 · 15 comments · Fixed by #5873
Closed

Building NSIS installers broken after switching from 22.10.5 to 22.11.1 #5863

ezzatron opened this issue May 6, 2021 · 15 comments · Fixed by #5873
Assignees

Comments

@ezzatron
Copy link
Contributor

ezzatron commented May 6, 2021

  • Version: 22.11.1
  • Electron Version: 12.0.6
  • Electron Type (current, beta, nightly): current
  • Target: Windows, NSIS, x64

After updating electron-builder from 22.10.5 to 22.11.1, this error started happening for all of our Windows builds:

  • packager.vm is used: Cannot read property 'readFileSync' of undefined
(node:90934) UnhandledPromiseRejectionWarning: Error: Exit code: ENOENT. spawn prlctl ENOENT
    at /path/to/project/node_modules/builder-util/src/util.ts:132:18
    at exithandler (child_process.js:315:5)
    at ChildProcess.errorhandler (child_process.js:327:5)
    at ChildProcess.emit (events.js:315:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:90934) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:90934) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

After some digging, this seems to be an issue with how app-builder-lib's TypeScript source is being compiled for distribution. The original source looks like this:

// ...

import fs from "fs"

// ...

export class UninstallerReader {
  // noinspection SpellCheckingInspection
  static exec(installerPath: string, uninstallerPath: string) {
    const buffer = fs.readFileSync(installerPath)

    // ...
  }
}

But in 22.11.1 this is being compiled to JavaScript that looks like this, where it expects the fs module to have a .default property, which it doesn't (basically assuming it's an ES module):

// ...

const fs_2 = require("fs");

// ...

class UninstallerReader {
    // noinspection SpellCheckingInspection
    static exec(installerPath, uninstallerPath) {
        const buffer = fs_2.default.readFileSync(installerPath); // <-- fs_2.default is undefined here

        // ...
    }
}

Looking at the distributed Javascript for the previous version (22.10.5), it seems like this case is handled by the compiled output:

// ...

var _fs2 = _interopRequireDefault(require("fs"));

// ...

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// ...

class UninstallerReader {
  // noinspection SpellCheckingInspection
  static exec(installerPath, uninstallerPath) {
    const buffer = _fs2.default.readFileSync(installerPath);

    // ...
  }

}

The _interopRequireDefault function seems to be something that used to be added by @babel/plugin-transform-modules-commonjs. My current theory is that something broke the Babel integration between these two versions.

@20vitality12
Copy link

20vitality12 commented May 7, 2021

Thank you! It`s help me to make build for win. 22.10.5 work fine

@mmaietta
Copy link
Collaborator

mmaietta commented May 8, 2021

Hmmm, the switch to pnpm from yarn also changed compilation from using ts-babel to tsc. ts-config was also changed from

    "target": "es2018",
    "module": "esnext",

to

"target": "es2019",
"module": "CommonJS",

@develar would you be able to take a look at this? Was this version also published differently, via pnpm?

@mmaietta
Copy link
Collaborator

Hi all. Can you please try v22.11.2?

@omarkilani
Copy link

@mmaietta 22.11.2 is still broken, and this is on macOS (we use 22.10.4 right now as 22.10.5 has some issue building native modules):

% git diff
diff --git a/package.json b/package.json
index 5e93206..2045da7 100644
--- a/package.json
+++ b/package.json
@@ -23,7 +23,7 @@
   "devDependencies": {
     "async": "^3.2.0",
     "electron": "^12.0.6",
-    "electron-builder": "22.10.4",
+    "electron-builder": "^22.11.2",
     "electron-builder-squirrel-windows": "^22.11.1",
     "electron-notarize": "^1.0.0",
     "electron-rebuild": "^2.3.5",
% yarn
yarn install v1.22.10
[1/4] 🔍  Resolving packages...
success Already up-to-date.
$ electron-builder install-app-deps
  • electron-builder  version=22.10.5
  • cannot check updates  error=TypeError: update_notifier_1.default is not a function
  • loaded configuration  file=package.json ("build" field)
  • installing production dependencies  platform=darwin arch=arm64 appDir=/blah/app
✨  Done in 1.44s.

Note how the version says 22.10.5 for some reason, even though we were on 22.10.4.

@ezzatron
Copy link
Contributor Author

Not working for me either. I get the same error. Perhaps it's to do with the esModuleInterop setting? I noticed that setting is explicitly set to false in electron-builder's config.

@stephanebouget
Copy link

Now it works with 22.11.3
tks !

@omarkilani
Copy link

This is, for whatever reason, still broken for us on 22.11.3, @develar .

% rm -rf node_modules 
% rm -rf app/node_modules 
% rm yarn.lock 
% rm app/yarn.lock
 
% yarn
yarn install v1.22.10
info No lockfile found.
[1/4] 🔍  Resolving packages...
warning electron-rebuild > lzma-native > node-pre-gyp@0.11.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
warning electron-rebuild > node-gyp > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning electron-rebuild > node-gyp > request > har-validator@5.1.5: this library is no longer supported
[2/4] 🚚  Fetching packages...
info google-closure-compiler-windows@20210505.0.0: The platform "darwin" is incompatible with this module.
info "google-closure-compiler-windows@20210505.0.0" is an optional dependency and failed compatibility check. Excluding it from installation.
info google-closure-compiler-windows@20210505.0.0: The CPU architecture "arm64" is incompatible with this module.
info google-closure-compiler-linux@20210505.0.0: The platform "darwin" is incompatible with this module.
info "google-closure-compiler-linux@20210505.0.0" is an optional dependency and failed compatibility check. Excluding it from installation.
info google-closure-compiler-linux@20210505.0.0: The CPU architecture "arm64" is incompatible with this module.
info google-closure-compiler-osx@20210505.0.0: The CPU architecture "arm64" is incompatible with this module.
info "google-closure-compiler-osx@20210505.0.0" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
success Saved lockfile.
$ electron-builder install-app-deps
  • electron-builder  version=22.10.5
  • loaded configuration  file=package.json ("build" field)
  • cannot check updates  error=TypeError: update_notifier_1.default is not a function
  • installing production dependencies  platform=darwin arch=arm64 appDir=/blah/app
✨  Done in 29.81s.

% fgrep version node_modules/electron-builder/package.json 
	"version": "22.11.3",

% node -v 
v16.1.0

% yarn -v
1.22.10

% npm -v
7.11.2

develar added a commit that referenced this issue May 11, 2021
@ezzatron
Copy link
Contributor Author

Can confirm that the original issue is now fixed for me. Thanks for the hard work 👍

@mmaietta
Copy link
Collaborator

@omarkilani , electron-builder 22.11.x currently does not work on node 16, not sure if it did previously in 22.10.
Ref: #5858 #5874

@omarkilani
Copy link

omarkilani commented May 12, 2021

@mmaietta ah, okay. Yeah it works great on 22.10.4.

#5668 (comment)

Forgot about that because I'm on a M1 Mac, though it looks like @develar made some other changes there that might help.

@omarkilani
Copy link

FWIW, 22.11.4 works, and appears to work on node 16. Thanks @develar !

@Stanzilla
Copy link

Stanzilla commented May 14, 2021

install-app-deps fails for me on 22.11.4

> electron-builder install-app-deps

Error: Cannot find module 'fs/promises'
Require stack:
- /home/runner/work/WeakAuras-Companion/WeakAuras-Companion/node_modules/builder-util/out/fs.js
- /home/runner/work/WeakAuras-Companion/WeakAuras-Companion/node_modules/builder-util/out/util.js
- /home/runner/work/WeakAuras-Companion/WeakAuras-Companion/node_modules/electron-builder/out/cli/cli.js
- /home/runner/work/WeakAuras-Companion/WeakAuras-Companion/node_modules/electron-builder/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/runner/work/WeakAuras-Companion/WeakAuras-Companion/node_modules/builder-util/src/fs.ts:4:1)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/runner/work/WeakAuras-Companion/WeakAuras-Companion/node_modules/builder-util/src/util.ts:24:1)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)

https://github.com/WeakAuras/WeakAuras-Companion/pull/1044/checks?check_run_id=2586016028

Edit: Updated node from 12 to 15 and it fixed it.

@angelnavarro
Copy link

Working with electron-builder 22.11.7 and node 14.17.3.

@sandeep1995
Copy link
Contributor

Doesn't work on Nodejs 12.21.0 32 bit on macOS.

Error: Cannot find module 'fs/promises' 

@mmaietta
Copy link
Collaborator

@sandeep1995 that's because newer versions of electron-builder requires node 14+

@electron-userland electron-userland locked as resolved and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
9 participants