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

Import the .node file in the main process and report an error #1302

Closed
zhouC98 opened this issue Mar 24, 2021 · 4 comments
Closed

Import the .node file in the main process and report an error #1302

zhouC98 opened this issue Mar 24, 2021 · 4 comments

Comments

@zhouC98
Copy link

zhouC98 commented Mar 24, 2021

Describe the bug
`
error in ./native/index.node

Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

@ ./src/background.js 15:0-44 16:12-21
@ multi ./src/background.js
`

Screenshots
image
image

Environment (please complete the following information):
"electron": "^9.0.0",
"electron-build-env": "^0.2.0",
"vue": "^2.6.11",
"native-ext-loader": "^2.3.0",
"neon-cli": "^0.6.0",
"vue-cli-plugin-electron-builder": "~2.0.0-rc.5",

@nklayman
Copy link
Owner

Can you please share the .node file you are using?

@zhouC98
Copy link
Author

zhouC98 commented Mar 27, 2021

您能否共享.node您正在使用的文件?
I use the template Vue-Webpack-Electron-Neon-Quickstart and the .node file generated by yarn build.
The generated .node file is used normally in main.js, and error is reported when used in background.js, as shown in the screenshot above.
Environment:
cargo 1.50.0
Python 2.7
xCode
neon 0.8.0
neon documentation

@d3x0r
Copy link

d3x0r commented Mar 31, 2021

This is the same issue I'm having with https://www.npmjs.com/package/sack.vfs. (on windows)
using plugin version ~2.0.0-rc.6

found this related issue: #610
#334

Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

 @ ./node_modules/sack.vfs/vfs_module.cjs 27:17-59 47:17-59
 @ ./node_modules/sack.vfs/vfs_module.mjs
 @ ./src/background.js
 @ multi ./src/background.js

the background.js just has

import {sack} from "sack.vfs";

It would be nice if .node files could just be used without any extra work... is this just because it's background and not main?

Also - if the .node had additional .DLLs associated with it, don't suppose those would be automatically included?

Edit: the current published version has additional issues with OpenSSL and Electron, and being rebuilt; there is an in-dev branch that works better; but still, the binary .node file isn't actually figured out.

Edit2: main.js and background.js behave the same way; so it's not just a background issue. I do wonder still if there's a Linux ELF/Windows PE detection issue... that a .node that's also PE doesn't work?

@nklayman
Copy link
Owner

The template repository you shared has some other issues with it that will cause an error, but to load the .node file in the main process you should add this to your vue.config.js:

// this goes inside of module.exports = {
pluginOptions: {
    electronBuilder: {
      nodeIntegration: true,
      chainWebpackMainProcess(config) {
        config.module
          .rule("node")
          .test(/\.node$/)
          .use("native-ext-loader")
          .loader("native-ext-loader")
          .options(
            process.env.NODE_ENV === "development"
              ? {
                  rewritePath: path.resolve(__dirname, "native"),
                }
              : {}
          )
      },
    },
  }

Your existing config only effected the renderer process, so it would work if you are importing the module into background.js.

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