首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到模块电子更新器

找不到模块电子更新器
EN

Stack Overflow用户
提问于 2022-09-27 13:54:39
回答 1查看 127关注 0票数 0

我遇到找不到模块电子更新程序的错误。

  • Electron-Builder版本:22.11.7
  • 节点版本: 14.17.4
  • Electron版本: 12.0.9
  • Electron-updater: 5.2.1
  • Target: windows

我安装了电子更新程序到依赖项。

代码语言:javascript
复制
"dependencies": {
        "@types/js-cookie": "^2.2.6",
         ...
        "electron-updater": "^5.2.1",

我用电子更新器打字。

代码语言:javascript
复制
import { app, BrowserWindow, ipcMain, dialog } from "electron";
import { autoUpdater } from "electron-updater";

因此,当我构建类型记录时,没有错误。但是我执行了这个应用程序,出现了错误。所以我试着修复一些代码。这是原始代码。我删除了!node_modules。在那之后,就没有错误了。

代码语言:javascript
复制
        "files": [
            "desktop/*",
            "build/**/*",
            "build-desktop/**/*",
            "!node_modules"
        ],

但是我不想添加node_modules,因为应用程序的大小增加了。这是用tsc --trace分辨率选项获取的日志。正如您可以看到的日志,当构建时,电子更新器被发现。但是为什么不能在运行时找到模块呢?

代码语言:javascript
复制
======== 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-upd

此列表是使用-listFiles选项获取的tsc编译文件。构建命令是

代码语言:javascript
复制
tsc desktop/main.ts --skipLibCheck --target es5 --outDir build-desktop --esModuleInterop
代码语言:javascript
复制
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

我检查了npm的生产,它有电子更新器。

代码语言:javascript
复制
+-- 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
EN

回答 1

Stack Overflow用户

发布于 2022-09-27 14:08:55

问题是,您正在排除node_modules文件夹。要理解这破坏构建的原因,您需要知道node_modules是存储应用程序的所有依赖项(即在package.jsondependency下定义的包)的地方。

因此,当排除该文件夹时,您正在告诉电子生成器不要复制应用程序的任何依赖项。因此,这些模块都找不到。

是的,node_modules将增加你的应用程序的大小,但这是你在应用程序中依赖第三方软件时必须接受的权衡。如果没有任何依赖项被复制到您的可发行应用程序中,则不能使用任何依赖项。

NPM告诉您使用npm ls --production (以及TypeScript编译器)所有这些模块的原因是,就NPM而言,您构建的应用程序不存在。NPM可以在调试(开发)模式和生产模式下运行您的应用程序,这两种模式都不涉及电子生成器。电子生成器只需要你的生产版本和包(“构建”)它的发行。

(请注意,这不适用于devDependencies,例如电子。电子生成器不会包含任何这些依赖项,因为只有在应用程序从源代码以调试模式运行时才需要这些依赖项。)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73868845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档