0

我试图加载robotjselectron但我不断收到一个恼人的Failed to compile错误。

我正在使用Vue.js界面,如果这很重要。

错误

 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)

node-loader我尝试使用to添加新规则,webpack但没有奏效。

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()],
};
4

1 回答 1

0

你需要告诉 webpack 不要包含robotjs在包中,而是需要它作为一个 commonjs 模块。

将此行添加到您的 webpack 配置文件中:

module.exports = {
  ...
  externals: {
    robotjs: 'commonjs robotjs',
  },
  ...
}

关于文档:https ://webpack.js.org/configuration/externals/#string

于 2021-08-18T09:58:35.093 回答