电子封装 - ASAR文件错误

时间:2016-04-12 14:47:53

标签: meteor electron asar

我正在使用Electrify包装Meteor应用程序(扩展名为Electron-Packager)。由于节点模块路径太深而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文件似乎有问题。你知道有什么方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

当您在应用程序中包含本机模块时,会发生 这种错误。本机模块需要针对构建应用程序的特定于操作系统的节点进行编译。因此,在压缩到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等)。希望这是有道理的。