Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silently Fails: Error running mksnapshot #71

Closed
seanaye opened this issue Nov 17, 2022 · 2 comments
Closed

Silently Fails: Error running mksnapshot #71

seanaye opened this issue Nov 17, 2022 · 2 comments

Comments

@seanaye
Copy link

seanaye commented Nov 17, 2022

I am receiving the following output when trying to create snapshot

Creating a linked script..
running in context
Generating startup blob in "/Users/seanaye/dev/coparse/pdf-reader/packages/app/cache"
Loading script for embedding: /Users/seanaye/dev/coparse/pdf-reader/packages/app/cache/snapshot.js
Error running mksnapshot.
Error: Error in mksnapshot
    at main (/Users/seanaye/dev/coparse/pdf-reader/packages/app/scripts/createSnapshot.js:49:11)

script to generate the snapshot

const childProcess = require('child_process');
const vm = require('vm');
const path = require('path');
const fs = require('fs');
const electronLink = require('electron-link');

const excludedModules = {};

async function main() {
  const baseDirPath = path.resolve(__dirname, '..');

  const mainPath = `${baseDirPath}/src/snapshot/imports.js`;

  console.log('Creating a linked script..');
  const result = await electronLink({
    baseDirPath: baseDirPath,
    mainPath,
    cachePath: `${baseDirPath}/cache`,
    shouldExcludeModule: (modulePath) =>
      excludedModules.hasOwnProperty(modulePath),
  });

  const snapshotScriptPath = `${baseDirPath}/cache/snapshot.js`;
  fs.writeFileSync(snapshotScriptPath, result.snapshotScript);

  // Verify if we will be able to use this in `mksnapshot`
  console.log('running in context');
  vm.runInNewContext(result.snapshotScript, undefined, {
    filename: snapshotScriptPath,
    displayErrors: true,
  });

  const outputBlobPath = path.resolve(__dirname, '../cache/');
  console.log(`Generating startup blob in "${outputBlobPath}"`);
  try {
    childProcess.execFileSync(
      path.resolve(
        __dirname,
        '..',
        'node_modules',
        '.bin',
        'mksnapshot' + (process.platform === 'win32' ? '.cmd' : '')
      ),
      [snapshotScriptPath, '--output_dir', outputBlobPath],
      { stdio: 'inherit' }
    );
  } catch {
    // actual errors go to stdio
    throw new Error("Error in mksnapshot")
  }
}

main().then(
  () => console.log('done'),
  (err) => console.error(err)
);

This was previously working fine. after re-downloading electron things stopped working. The script executes correctly in runInNewContext as well

contents of the snapshot/imports.js file

require("react")
require("react-dom")

Resolved package versions
"electron-mksnapshot": "^21.0.0",
"electron": "^21.2.3",
"electron-link": "^0.6.0",

System info:
MacOS 12.6 arm64

@craftzdog
Copy link

Had the same issue, but looks like it's been already resolved here: electron/electron#36378

@jkleinsc
Copy link
Contributor

jkleinsc commented Dec 1, 2022

@jkleinsc jkleinsc closed this as completed Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants