electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.65k stars 1.74k forks source link

cannot find module electron updater #7147

Closed deco-dev closed 2 years ago

deco-dev commented 2 years ago
I encountered cannot find module electron updater error.

image First I installed electron-updater to dependencies.

"dependencies": {
        "@emotion/react": "^11.8.2",
        "@material-ui/core": "^4.11.3",
        "@material-ui/data-grid": "^4.0.0-alpha.26",
        "@material-ui/icons": "^4.11.2",
        "@material-ui/lab": "^4.0.0-alpha.57",
        "@mui/material": "^5.5.1",
        "@testing-library/jest-dom": "^5.11.10",
        "@testing-library/react": "^11.2.6",
        "@testing-library/user-event": "^12.8.3",
        "@types/jest": "^26.0.22",
        "@types/js-cookie": "^2.2.6",
         ...
        "electron-updater": "^5.2.1",

And I used electron updater to typescript.

import { app, BrowserWindow, ipcMain, dialog } from "electron";
import { autoUpdater } from "electron-updater";

So when I built typescript, There is no error. But I executed the app, the error occurred. So I try to fix some code. This is orignal code. I removed the !node_modules. After that, there is no error.

        "files": [
            "desktop/*",
            "build/**/*",
            "build-desktop/**/*",
            "!node_modules"
        ],

But I don't want to add node_modules because the app size is increased. This is log that gets with tsc --traceResolution option. As you can see the log, when build time, electron-updater is found. But why can not found the module on runtime?

======== Resolving module 'electron-updater' from 'D:/DI/front-end/desktop/main.ts'. ========
Resolving real path for 'D:/DI/front-end/node_modules/electron-updater/out/main.d.ts', result 'D:/DI/front-end/node_modules/electron-updater/out/main.d.ts'.
======== Module name 'electron-updater' was successfully resolved to 'D:/DI/front-end/node_modules/electron-updater/out/main.d.ts' with Package ID 'electron-updater/out/main.d.ts@5.2.1'. ========
deco-dev commented 2 years ago

This list is tsc compiled files that gets with--listFiles option.

D:/DI/front-end/node_modules/electron-updater/out/AppAdapter.d.ts
D:/DI/front-end/node_modules/electron-updater/out/DownloadedUpdateHelper.d.ts
D:/DI/front-end/node_modules/electron-updater/out/electronHttpExecutor.d.ts
D:/DI/front-end/node_modules/electron-updater/out/providers/Provider.d.ts
D:/DI/front-end/node_modules/typed-emitter/index.d.ts
D:/DI/front-end/node_modules/electron-updater/out/AppUpdater.d.ts
D:/DI/front-end/node_modules/electron-updater/out/BaseUpdater.d.ts
D:/DI/front-end/node_modules/electron-updater/out/AppImageUpdater.d.ts
D:/DI/front-end/node_modules/electron-updater/out/MacUpdater.d.ts
D:/DI/front-end/node_modules/electron-updater/out/NsisUpdater.d.ts
D:/DI/front-end/node_modules/electron-updater/out/main.d.ts
D:/DI/front-end/desktop/socketClient.ts
deco-dev commented 2 years ago

This is my build command.

"desktop-tsc": "tsc desktop/main.ts --skipLibCheck --target es5 --outDir build-desktop --esModuleInterop",

I execute npm run desktop-tsc && electron-builder --win

deco-dev commented 2 years ago

I checked the npm ls --production, it has electron-updater.

+-- electron-updater@5.2.1
| +-- @types/semver@7.3.12
| +-- builder-util-runtime@9.0.3
| | +-- debug@4.3.4
| | | `-- ms@2.1.2 deduped
| | `-- sax@1.2.4
| +-- fs-extra@10.1.0
| | +-- graceful-fs@4.2.6
| | +-- jsonfile@6.1.0
| | | +-- graceful-fs@4.2.6 deduped
| | | `-- universalify@2.0.0 deduped
| | `-- universalify@2.0.0
| +-- js-yaml@4.1.0
| | `-- argparse@2.0.1
| +-- lazy-val@1.0.5
| +-- lodash.escaperegexp@4.1.2
| +-- lodash.isequal@4.5.0
| +-- semver@7.3.7
| | `-- lru-cache@6.0.0
| |   `-- yallist@4.0.0
| `-- typed-emitter@2.1.0
|   `-- rxjs@7.5.7
|     `-- tslib@2.4.0
+-- js-cookie@2.2.1
mmaietta commented 2 years ago

You shouldn't explicitly exclude "!node_modules" as that's deliberately blocking the asset from being bundled in the asar. electron-builder should automatically parse your node_modules and only pack the ones that are production dependencies

KVAnton-WEB commented 1 year ago

Did you find a solution? I have a similar problem one with rxjs

OldManMeta commented 1 year ago

The solution I found was to add a postinstall option:

"package": "electron-builder", "postinstall": "electron-builder install-app-deps"