1

我正在使用 Electrify(通过扩展 Electron-Packager)打包 Meteor 应用程序。由于节点模块路径太深,Windows 无法接受,因此我添加了“--asar=true”作为打包选项。

现在,当我尝试启动打包的应用程序时,出现以下错误:

shell.js: internal error
Error: ENOENT: no such file or directory, mkdir 'C:\Users\myusername\MyApp\.electrify\.dist\MyApp-win32-x64\resources\app.asar\db'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:799:18)
    at mkdirSyncRecursive 

...

        at Socket.g (events.js:260:16)
    module.js:338
        throw err;

读取asar文件似乎有问题。你知道有什么方法可以解决这个问题吗?

4

1 回答 1

1

当您在应用程序中包含本机模块时,可能会发生这种错误。本机模块需要针对构建应用程序的操作系统特定节点进行编译。因此,当您压缩到 ASAR 时,您必须排除项目中的任何本机模块。这是通过在整个打包程序选项中的 'asar' 选项中的 unpackDir 选项完成的。例如,在我的 gulp 构建中,我执行以下操作:

var gulp = require('gulp');
var $ = require('gulp-load-plugins')({lazy: true});
var config = require('./gulp.config')();
var packager = require('electron-packager');
var electronPackage = require('electron/package.json');
var electronVersion = electronPackage.version;
var pkg = require('./package.json');

// Build the electron app
gulp.task('build:electron', function(cb) {

    var opts = {
        name: pkg.name,
        platform: 'win32',
        arch: 'ia32',                           // ia32, x64 or all
        dir: config.root,                       // source location of app
        out: config.electronbuild,              // destination location for app os/native binaries
        ignore: config.electronignore,          // don't include these directories in the electron app build
        icon: config.icon,
        asar: {unpackDir: config.electroncompiled}, // compress project/modules into an asar blob but don't use asar to pack the native compiled modules
        overwrite: true,
        prune: true,
        electronVersion: electronVersion,       // Tell the packager what version of electron to build with
        'app-copyright': pkg.copyright,         // copyright info
        'app-version': pkg.version,             // The version of the application we are building
        win32metadata: {                        // Windows Only config data
            CompanyName: pkg.authors,
            ProductName: pkg.name,
            FileDescription: pkg.description,
            OriginalFilename: pkg.name + '.exe'
        }
    };

    packager(opts, function(err, appPath) {
        $.util.log(' <- packagerDone()', err, appPath);
        log(' all done!');
        cb();
    });

});

对您的情况重要的是 asar 选项的行。您要确保执行类似 的操作asar: {unpackDir: config.electroncompiled},并简单地将config.electroncompiled变量替换为包含项目使用的任何本机编译包的目录文件 glob(例如libxml-xsd,libxmljs-mtnslog)。希望这是有道理的。

于 2017-01-20T00:30:30.147 回答