webpack-contrib / node-loader

node loader for native modules
MIT License
119 stars 43 forks source link

Electron not able to read .node files #59

Closed webpack-bot closed 1 month ago

webpack-bot commented 3 years ago

Im trying to load robotjs with electron but I keep getting an annoying Failed to compile error.

I'm using Vue.js for the interface, if that matters.

The error

 error  in ./node_modules/robotjs/build/Release/robotjs.node

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)

I tried adding a new rule using node-loader to webpack but that didn't work.

import MiniCssExtractPlugin from "mini-css-extract-plugin";

module.exports = {
  mode: "development",
  devtool: "source-map",
  target: "node",
  node: {
    __dirname: false,
  },
  resolve: {
    extensions: [".ts", ".js"],
  },
  module: {
    rules: [
      {
        test: /\.node$/,
        loader: "node-loader",
      },
      {
        test: /\.ts$/,
        exclude: /node_modules/,
        use: {
          loader: "ts-loader",
        },
      },
      {
        test: /\.scss$/,
        use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
      },
    ],
  },
  plugins: [new MiniCssExtractPlugin()],
};

This issue was moved from webpack/webpack#14012 by @alexander-akait. Original issue was by @leobezr.

alexander-akait commented 3 years ago

@leobezr Can you provide steps to reproduce?

leobezr commented 3 years ago

@leobezr Can you provide steps to reproduce?

Repository

Link to repository

First step

Generate a Vue project with Vue CLI

$ vue create project-name

Configuration used:

Second step

Add electron to project

$ vue add electron-builder

Third step

Add robotjs to project

$ yarn add robotjs

Fourth step

Import robotjs inside Vue component.

import robot from "robotjs";

That should break the compiler when serving the project.

alexander-akait commented 3 years ago

Sorry, can't run reproducible repo:

make: Entering directory '/home/evilebottnawi/IdeaProjects/bezrbot/node_modules/robotjs/build'
  CXX(target) Release/obj.target/robotjs/src/robotjs.o
cc1plus: warning: command line option ‘-Wbad-function-cast’ is valid for C/ObjC but not for C++
In file included from ../src/keypress.h:6,
                 from ../src/robotjs.cc:7:
../src/keycode.h:112:10: fatal error: X11/Xutil.h: No such file or directory
  112 | #include <X11/Xutil.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
leobezr commented 3 years ago

Well thats weird, did you try creating a new repo?

alexander-akait commented 3 years ago

Same problem due robotjs, What is your os and version?

leobezr commented 3 years ago

Windows 10 @vue/cli 4.5.11 node v14.16.0

alexander-akait commented 3 years ago

h, weirds, should be compiled... maybe vue-cli already handle node extension, can you check it? just remove loader

leobezr commented 3 years ago

h, weirds, should be compiled... maybe vue-cli already handle node extension, can you check it? just remove loader

Can't you just make the changes to try and run it ? I'm not sure what loader you're referring to, is it node-loader?

Also, are you running e:dev for electron build?

alexander-akait commented 3 years ago

I can't run due impossible to install, maybe you can try to reproduce it without vue-cli?

jamesplease commented 2 years ago

Just wanted to pop in here to share that I'm encountering this same issue. I'm on Windows 11.

fanchenio commented 2 years ago

@leobezr Is it resolved please? I also have the same problem.

leobezr commented 2 years ago

@leobezr Is it resolved please? I also have the same problem.

Not at the time, I just gave up on this project, my suggestion is, if your using robotjs, just use Python instead.

fanchenio commented 2 years ago

@leobezr All right, thank you.

alexander-akait commented 1 month ago

Closing due to inactivity. Please test with latest version and feel free to reopen if still regressions. Thanks!