-
Hey, so I'm trying to write a plugin that uses bluetooth LE, using this library: https://github.com/thegecko/webbluetooth I have a PoC of the bluetooth code running outside the plugin, but as soon as I add this to the plugin code:
I get the exclamation mark icon, and the logs on my mac shows the constant restarting behaviour below. Is there something about the plugin environment (presumably it's just Node?) that prevents libraries with native bindings from working?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @superslau, Sometimes you can run into issues where import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import nodeResolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import path from "node:path";
import url from "node:url";
import copy from "rollup-plugin-copy";
import del from "rollup-plugin-delete";
const isWatching = !!process.env.ROLLUP_WATCH;
/**
* @type {import('rollup').RollupOptions}
*/
const config = {
input: "src/plugin.ts",
output: {
file: "com.elgato.volume-controller.sdPlugin/bin/plugin.js",
sourcemap: isWatching,
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
return url.pathToFileURL(path.resolve(path.dirname(sourcemapPath), relativeSourcePath)).href;
},
format: "cjs"
},
plugins: [
del({ targets: "com.elgato.volume-controller.sdPlugin/bin/addons" }),
json(),
typescript({
mapRoot: isWatching ? "./" : undefined
}),
nodeResolve({
browser: false,
exportConditions: ["node"],
preferBuiltins: true
}),
{
name: "napi-watch",
buildStart: function () {
this.addWatchFile("build/Release");
}
},
commonjs({
ignoreDynamicRequires: true
}),
copy({
copyOnce: true,
errorOnExist: false,
overwrite: false,
targets: [
{
src: "node_modules/@img/",
dest: "com.elgato.volume-controller.sdPlugin/bin/node_modules"
}
]
}),
copy({
targets: [
{
src: "build/Release/*.node",
dest: "com.elgato.volume-controller.sdPlugin/bin/addons"
}
]
}),
!isWatching && terser(),
{
name: "emit-module-package-file",
generateBundle() {
this.emitFile({
fileName: "package.json",
source: `{ "type": "commonjs" }`,
type: "asset"
});
}
}
]
};
export default config; I have also seen developers add and install the module to the Best, |
Beta Was this translation helpful? Give feedback.
Hi @superslau,
Sometimes you can run into issues where
npm
packages are meant to be using in the web environment, although it appears that this package should work within Node. Native addons should work for you (Elgato uses them in the Volume Controller plugin), but you will need to include the module inside of the plugin folder. In Volume Controller, we use a rollup plugincopy
to move the files into the plugin foldercom.elgato.volume-controller.sdPlugin/bin/node_modules
.