How to require node addon(c++) in a quasar electron project
-
i have a c++ node addon and build as node file
when i require this node file
webpack node-loader popup an error
said “The specified module could not be found.”
and the node file name changed to [filehash].node
like “src-electron\main-process/100b783793116bc6eb2cabbd8bd066d9.node”how to deal with it?
-
I think you’re better of asking this specialized question in electron forums/communities:
-
@dobbel this error come with webpack’s node-loader error
if only use electron without wepack it’s gonna work -
setting node.__dirname to false works for me !
// quasar.conf
electron: {
extendWebpack (cfg) {
// do something with Electron main process Webpack cfg
// chainWebpack also available besides this extendWebpack
console.log("<<<<<<<<<<<<<<<<<<<<<<<<");
cfg.node.__dirname=false; // set node-loader’s node.__dirname to false, according to node-loader github document
console.log(cfg.node);
}
} -
@ly this is not work for me. any detail.
-
not work for me either:
"scripts": { "lint": "eslint --ext .js,.vue ./", "test": "echo \"No test specified\" && exit 0", "dev-spa": "quasar dev", "dev-macos": "quasar dev -T darwin -m electron", "build-macos": "quasar build -T darwin -m electron", "inspect-macos": "quasar inspect -T darwin -m electron", "dev-win": "quasar dev -T win32 -m electron", "build-win": "quasar dev -T win32 -m electron" }, "dependencies": { "@cloudbase/js-sdk": "^1.4.1", "@quasar/extras": "^1.0.0", "axios": "^0.21.1", "core-js": "^3.6.5", "quasar": "^1.0.0", "trtc-electron-sdk": "^8.4.1" }, "devDependencies": { "@quasar/app": "^2.0.0", "@quasar/cli": "^1.1.3", "babel-eslint": "^10.0.1", "devtron": "^1.4.0", "electron": "^9.0.0", "electron-debug": "^3.0.1", "electron-devtools-installer": "^3.0.0", "electron-packager": "^14.1.1", "eslint": "^7.21.0", "eslint-config-prettier": "^8.1.0", "eslint-plugin-vue": "^7.7.0", "eslint-webpack-plugin": "^2.4.0", "native-ext-loader": "^2.3.0" },
-
is there an example for quasar + electron + native dependency library?
-
-
Did you do anything else? I’m having the same issue with sharp and adding those lines simply gave me the same error with a different filename;
Error: The specified module could not be found. node_modules\sharp\build\Release/sharp.node
Even though that file definitely exists at that location.
-
@cppgohan it worked. thank you very much.
-
Anyone else reading might be helped by the following thread;
https://github.com/lovell/sharp/issues/2646In my case, sharp needed to be configured in webpack’s externals, but quasar’s abstraction was a bit hard to navigate since most instructions expect a webpack.config file. The above helped me a lot, even though it may seem simple.
-
Adding it to externals, for me, required putting the following inside chainWebpack under build in quasar.conf.js
chain.externals({ 'sharp': 'commonjs sharp' })