node-loader icon indicating copy to clipboard operation
node-loader copied to clipboard

Electron not able to read .node files

Open webpack-bot opened this issue 4 years ago • 13 comments

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.

webpack-bot avatar Aug 17 '21 13:08 webpack-bot

@leobezr Can you provide steps to reproduce?

alexander-akait avatar Aug 17 '21 13:08 alexander-akait

@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:

  • Babel
  • Typescript
  • Router
  • Vuex
  • CSS Pre-processors (Scss)
  • Unit Testing
  • Linter / Formatter

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.

leobezr avatar Aug 17 '21 15:08 leobezr

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.

alexander-akait avatar Aug 20 '21 11:08 alexander-akait

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

leobezr avatar Aug 20 '21 14:08 leobezr

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

alexander-akait avatar Aug 20 '21 14:08 alexander-akait

Windows 10 @vue/cli 4.5.11 node v14.16.0

leobezr avatar Aug 20 '21 14:08 leobezr

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

alexander-akait avatar Aug 20 '21 15:08 alexander-akait

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?

leobezr avatar Aug 20 '21 15:08 leobezr

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

alexander-akait avatar Aug 21 '21 13:08 alexander-akait

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

jamesplease avatar Jun 02 '22 01:06 jamesplease

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

fanchenio avatar Oct 24 '22 09:10 fanchenio

@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.

leobezr avatar Oct 24 '22 10:10 leobezr

@leobezr All right, thank you.

fanchenio avatar Oct 24 '22 10:10 fanchenio