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

electron-forge to package ,return code of 0x80070002 #19

Closed
eug3 opened this issue Sep 16, 2024 · 10 comments
Closed

electron-forge to package ,return code of 0x80070002 #19

eug3 opened this issue Sep 16, 2024 · 10 comments

Comments

@eug3
Copy link

eug3 commented Sep 16, 2024

When using electron-forge to package and distribute the project, the following error occurs:

uncaughtException: Error: Call to coreclr_create_delegate() for G failed with a return code of 0x80070002

However, it works fine with npm start.

This is on a Windows 11 environment.

@agracio
Copy link
Owner

agracio commented Sep 16, 2024

When packaging electron application electron-edge-js should be excluded from asar archive and copied into node_modules with its dependencies.

Take a look at some examples here: Packaging Electron application

@eug3
Copy link
Author

eug3 commented Sep 16, 2024

I have already made this configuration:

packagerConfig: {
    asar: true,
    asarUnpack: [
      'node_modules/electron-edge-js/**'   
    ]
  },
  hooks: {
    // hook afterCopy  
    async afterCopy(buildPath, electronVersion, platform, arch) {
      const src = path.join(__dirname, 'node_modules', 'electron-edge-js');
      const dest = path.join(buildPath, 'node_modules', 'electron-edge-js');
      
      // copy electron-edge-js  
      await fs.copy(src, dest);
    }
  }

image

However, it still throws an error.

@agracio
Copy link
Owner

agracio commented Sep 16, 2024

As per my previous comment electron-edge-js should not be packed into asar archive in the first place, take a look at your webpack config for electron-forge. If you still have this issue create a repo to reproduce and I will take a look at it.

@eug3
Copy link
Author

eug3 commented Sep 16, 2024

https://github.com/eug3/e/tree/master

This is my code. Thanks for the help.

@agracio
Copy link
Owner

agracio commented Sep 16, 2024

I am not very familiar with electron-forge and from quick look it does not appear that you can exclude modules from being packed into asar archive. asarUnpack option is not going to help since it suppose to contain node_modules next to app.asar. In node_modules you would have electron-edge-js and edge-cs .
You need to figure out how to create such package.

@agracio
Copy link
Owner

agracio commented Sep 16, 2024

npm start does not work either since it is trying to rebuild electron-edge-js but it should be excluded from rebuild.
For it to work modify your forge.config.js to include

rebuildConfig: {
    onlyModules: [],
  },

@eug3
Copy link
Author

eug3 commented Sep 17, 2024

Based on your suggestions, I made some modifications. Although it's not very elegant, it works smoothly after running npm run make.

This is how I did it:

packagerConfig: {
  asar: {
    unpackDir: "net8.0", // This is where the C# dynamic libraries are located
  },
  ignore: ["node_modules/electron-edge-js", "node_modules/edge-cs"],
},
hooks: {
  postPackage: async (forgeConfig, options) => {
    console.log("build_path", options.outputPaths);
    const outdir = options.outputPaths[0];
    console.log("outdir", outdir);

    // Get node_modules path
    const nodeModulesPath = path.join(outdir, "resources", "node_modules"); 
    const modulesToCopy = ["edge-cs", "electron-edge-js"];

    for (const moduleName of modulesToCopy) {
      const sourcePath = path.join(__dirname, "node_modules", moduleName);
      const targetPath = path.join(nodeModulesPath, moduleName);
      console.log(
        `Copying ${moduleName} from:`,
        sourcePath,
        "to:",
        targetPath
      );
      fs.copySync(sourcePath, targetPath);
    }
    console.log("All modules copied successfully!");
  },
},
... // other properties

Since the dynamic libraries are packed into the app.asar.unpacked directory, I added a check when calling them:

if(__dirname.indexOf('app.asar') !== -1) {
  baseNetAppPath = path.join(process.resourcesPath, "app.asar.unpacked", "net8.0");
}

With this approach, it now works smoothly on Windows 11. Thanks for the help!

@eug3 eug3 closed this as completed Sep 17, 2024
@agracio
Copy link
Owner

agracio commented Sep 17, 2024

I tried running your updated repo on my Win 10 PC and it fails with same message as before.

TypeError: Cannot read properties of undefined (reading 'replace')

EDIT: resolved by changing one line in both main.js and app.js. This is needed because we are no longer sending --core or --standard parameter on start.

main.js

var version = 'core';

app.js

var net = 'core';

@agracio
Copy link
Owner

agracio commented Sep 17, 2024

Created electron-forge example based on your repo, you are credited in README.
https://github.com/agracio/electron-edge-js-quick-start-forge

@agracio
Copy link
Owner

agracio commented Sep 18, 2024

Found another way to simplify electron-forge config

``forge.config.js`

packagerConfig: {
    asar: true ,
    ignore: ["node_modules/electron-edge-js", "node_modules/edge-cs"],
    extraResource: [
      "net8.0/",
    ]
  }

app.js

 if (__dirname.indexOf("app.asar") !== -1) {
    baseNetAppPath = path.join(process.resourcesPath,"net8.0");
  }

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

2 participants