简体   繁体   English

使用 electron-builder 导入用户 js 文件时出错

[英]Error importing a user js file using electron-builder

I have an electron application with main process as follows:我有一个电子申请,主要流程如下:

const {app, BrowserWindow, Menu, dialog} = require('electron');
const path = require('path')
let logConfig = require('./js/loggConfig.js');
....

This executes perfectly when run directly from terminal.当直接从终端运行时,这可以完美执行。
But when I package this project using electron-builder, and install it on another machine (Windows 10), I get the following error while launching the app: Error: Cannot find module '.js/loggConfig.js'但是当我使用 electron-builder 打包这个项目并将其安装在另一台机器(Windows 10)上时,我在启动应用程序时收到以下错误: Error: Cannot find module '.js/loggConfig.js'

How do I resolve this?我该如何解决这个问题?

Here is how my package.json looks like:这是我的package.json的样子:

{
  "name": "ABCD",
  "version": "0.0.1",
  "description": "...",
  "author": "abcd <abcd@gmail.com>",
  "homepage": "http://www.abcd.com",
  "main": "main_electron.js",
  "scripts": {
    "postinstall": "install-app-deps",
    "start": "electron .",
    "dist": "build"
  },
  "build": {
    "appId": "yourappid",
    "dmg": {
      "contents": [
        {
          "x": 110,
          "y": 150
        },
        {
          "x": 240,
          "y": 150,
          "type": "link",
          "path": "/Applications"
        }
      ]
    },
    "linux": {
      "target": [
        "AppImage",
        "deb"
      ],
      "category": "Video"
    },
    "win": {
      "target": "NSIS",
      "icon": "build/icon.ico",
      "extraResources": [
      ]
    }
  },
  "dependencies": {
    "electron-context-menu": "^0.9.1",
    "electron-log": "^2.2.13",
    "fs": "0.0.1-security",
    "mkdirp": "^0.5.1",
    "path": "^0.12.7",
    "uuid": "^3.1.0",
    "xmlbuilder": "^9.0.4",
    "zip-folder": "^1.0.0"
  },
  "devDependencies": {
    "electron": "^1.7.9",
    "electron-builder": "^19.49.0"
  }
}

I solved the issue changing the build configuration.我解决了更改构建配置的问题。

  • Setting asar to false .asar设置为false
  • Setting asarUnpack to export all the asar content with "**/*" .设置asarUnpack以使用"**/*"导出所有asar内容。
     "build": {
        "appId": "app.node.electron",
        "productName": "app electron",
        "asar":false,
        "asarUnpack":[
          "**/*"
        ],
        "directories": {
          "output": "release"
        },
        "win": {
          "publisherName": "app electron",
          "icon": "icon.png",
          "target": [
            "nsis"
          ]
        },
      },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 放入文件服务器时,electron-vue会产生电子包装程序和电子生成程序错误 - electron-packager and electron-builder error build with electron-vue when put in file server 使用电子生成器将文件夹和其中的文件包含到电子构建中? - Include a folder and the files inside it to electron build using electron-builder? 使用 electron-builder 和 webpack 在 main.js 中使用 node-modules - Using node-modules in main.js using electron-builder and webpack 在使用电子构建器安装应用程序的同时向用户环境添加命令行脚本 - Adding a command line script to the user environment whilst installing an application using electron-builder 如何在Electron-builder中使用相对路径包含Node.js模块 - How to include a Node.js module using a relative path with Electron-builder OpenCV.js 不工作 vue.js (electron-builder) - OpenCV.js is not working vue.js (electron-builder) 来自电子构建器的 AppImage 文件系统不起作用 - AppImage from electron-builder with file system not working 在电子构建器中检索或指定输出文件名 - Retrieve or Specify output file name in electron-builder 如何使用电子生成器将 v8 快照打包到 exe 中? - How to pack v8 snapshot into exe using electron-builder? 如何分发使用电子构建器构建的构建可执行文件 - How to distribute a built executable constructed using electron-builder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM