umbrella22 / electron-vite-template

This project is a vue3 + Vite + electron project template composed of Vite and rollup. It has the same functions as my previous electron+Vue+template project
Other
418 stars 111 forks source link

Error when trying to use `native-reg` with this package (windows only) #131

Closed KSneijders closed 5 months ago

KSneijders commented 5 months ago

When adding native-reg to this template I get the following error:

Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=121 uv=1 libc=glibc node=20.9.0 electron=29.1.6
  loaded from: C:\Users\_USER_\Documents\Projects\Electron\electron-vite-template\dist\electron

  at load.resolve.load.path (C:\Users\_USER_\Documents\Projects\Electron\electron-vite-template\dist\electron\main\main.js:19874:10)
  at load (C:\Users\_USER_\Documents\Projects\Electron\electron-vite-template\dist\electron\main\main.js:19836:31)
  at C:\Users\_USER_\Documents\Projects\Electron\electron-vite-template\dist\electron\main\main.js:20050:49
  at Object.<anonymous> (C:\Users\_USER_\Documents\Projects\Electron\electron-vite-template\dist\electron\main\main.js:20374:3)
  at Module._compile (node:internal/modules/cjs/loader:1256:14)
  at Module._extensions..js (node:internal/modules/cjs/loader:1311:10)
  at Module.load (node:internal/modules/cjs/loader:1098:32)
  at Module._load (node:internal/modules/cjs/loader:945:12)
  at c._load (node:electron/js2c/node_init:2:13672)
  at cjsLoader (node:internal/modules/esm/translators:288:17)

This error comes from native-reg itself, so I've raised an issue on their end too. The owner of the package said the following:

My best guess here, given that's a JavaScript stack, is that your bundler configuration isn't putting the binary .node file in the right place? [...] it should only need to be copied to the output/distribution directory for builds, I'm less sure about what vite dev would expect....

I'm not familiar with this process at all and was wondering if you could help out? I love the template and would love to use it. But this issue is beyond what I know about building node binaries and vite internals.

Thanks in advance!

mlmdflr commented 5 months ago

You need to add the following configuration inside rollup.config.ts in the .electron-vite folder image

KSneijders commented 5 months ago

@mlmdflr Wow, that's a simple solution! If you don't mind me asking, what's the reason why the library has to be listed here?

I'm asking, because to fix the issue we tried another registry library and that worked without adding it to this list. So, what's the criteria for a library to have to be listed here?

mlmdflr commented 5 months ago

@mlmdflr Wow, that's a simple solution! If you don't mind me asking, what's the reason why the library has to be listed here?

I'm asking, because to fix the issue we tried another registry library and that worked without adding it to this list. So, what's the criteria for a library to have to be listed here?

What's the name of the other library you're using?

KSneijders commented 5 months ago

@mlmdflr Wow, that's a simple solution! If you don't mind me asking, what's the reason why the library has to be listed here? I'm asking, because to fix the issue we tried another registry library and that worked without adding it to this list. So, what's the criteria for a library to have to be listed here?

What's the name of the other library you're using?

https://github.com/fresc81/node-winreg

mlmdflr commented 5 months ago

@mlmdflr Wow, that's a simple solution! If you don't mind me asking, what's the reason why the library has to be listed here? I'm asking, because to fix the issue we tried another registry library and that worked without adding it to this list. So, what's the criteria for a library to have to be listed here?

What's the name of the other library you're using?

https://github.com/fresc81/node-winreg

My English is not very good and I can only explain this with the help of translation tools First of all, the code implementation of these two libraries is not the same, node-winreg is using some windows command line to access the registry through the child_process module. native-reg is a bit more complicated, I don't know much about c++, but I know that native-reg calls win32Api, which is essentially a native module. This scaffolding uses rollup to package the code of the main process, you need to specify the external dependencies, otherwise there will be a series of problems such as paths. The implementation of node-winreg is simple, it only uses a js file, it doesn't need any special processing, you can take a look at the source code, it's a good library.

KSneijders commented 5 months ago

@mlmdflr Aah, that makes sense.

I'll do some more reading on it. Thank you for taking a look for me! ❤️