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

Build Error - [Different Node.js version]

Open panda6412 opened this issue 6 years ago • 21 comments

When I try to build with electron, encounter below error, Am I version wrong ? or there's has another reason cause it?

Error: The module '/Users/yang/Desktop/electron_practice/electron-react/print-server/node_modules/printer/build/Release/node_printer.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 67. This version of Node.js requires
NODE_MODULE_VERSION 70. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at process.func [as dlopen] (electron/js2c/asar.js:155:31)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:850:18)
    at Object.func [as .node] (electron/js2c/asar.js:155:31)
    at Module.load (internal/modules/cjs/loader.js:677:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:609:12)
    at Function.Module._load (internal/modules/cjs/loader.js:601:3)
    at Module.require (internal/modules/cjs/loader.js:715:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/Users/yang/Desktop/electron_practice/electron-react/print-server/node_modules/printer/lib/printer.js:10:22)
    at Module._compile (internal/modules/cjs/loader.js:808:30)

I've followed the suggesstion, but it does not work, also ...


Build env version below:

yarn - 1.15.2 node - v12.0.0 electron - 5.0.0

panda6412 avatar Apr 29 '19 04:04 panda6412

I am having a similar problem but using electron 6

patrickrobbins avatar May 30 '19 16:05 patrickrobbins

I am having a similar problem but using electron 6

I downgrade node to v10.15.3, then fix it

panda6412 avatar Jun 01 '19 03:06 panda6412

Tried these 4 steps from Electron website? Most of the time just electron-rebuild -f -w printer helps (don't forget to read the instructions).

henrymazza avatar Jun 15 '19 15:06 henrymazza

I know I'm a little late to the party here, but in case anyone else sees this, you have to go into the node_modules/printer folder and run the following command with the target version set to your electron version, so that it gets built with the node.js version used by Electron rather than your system node.js version. I got this from the electron documentation.

node-gyp rebuild --target=5.0.7 --arch=x64 --dist-url=https://electronjs.org/headers

MikeVermilion avatar Jul 22 '19 23:07 MikeVermilion

@MikeVermilion Hi, I'm trying to install, First i installed electron then printer, when i go to node_modules/printer folder and run: node-gyp rebuild --target=5.0.7 --arch=x64 --dist-url=https://electronjs.org/headers I get some warnings and these errors: `In file included from ../src/node_printer.cc:1:0: ../src/node_printer.hpp: At global scope: ../src/node_printer.hpp:121:39: error: ‘Handle’ is not a member of ‘v8’ bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^~~~~~ ../src/node_printer.hpp:121:55: error: expected primary-expression before ‘>’ token bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^ ../src/node_printer.hpp:121:57: error: ‘iV8Value’ was not declared in this scope bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^~~~~~~~ ../src/node_printer.hpp:121:79: error: expected primary-expression before ‘&’ token bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^ ../src/node_printer.hpp:121:80: error: ‘oData’ was not declared in this scope bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^~~~~ ../src/node_printer.hpp:121:85: error: expression list treated as compound expression in initializer [-fpermissive] bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^ ../src/node_printer.cc:5:19: error: variable or field ‘initNode’ declared void void initNode(v8::Handlev8::Object exports) { ^~~~~~ ../src/node_printer.cc:5:19: error: ‘Handle’ is not a member of ‘v8’ ../src/node_printer.cc:5:36: error: expected primary-expression before ‘>’ token void initNode(v8::Handlev8::Object exports) { ^ ../src/node_printer.cc:5:38: error: ‘exports’ was not declared in this scope void initNode(v8::Handlev8::Object exports) { ^~~~~~~ In file included from ../src/node_printer.hpp:6:0, from ../src/node_printer.cc:1: ../src/node_printer.cc:19:27: error: ‘initNode’ was not declared in this scope NODE_MODULE(node_printer, initNode); ^ /home/df/.cache/node-gyp/5.0.7/include/node/node.h:560:36: note: in definition of macro ‘NODE_MODULE_X’ (node::addon_register_func) (regfunc),
^~~~~~~ ../src/node_printer.cc:19:1: note: in expansion of macro ‘NODE_MODULE’ NODE_MODULE(node_printer, initNode); ^~~~~~~~~~~ ../src/node_printer.cc:19:27: note: suggested alternative: ‘initstate’ NODE_MODULE(node_printer, initNode); ^ /home/df/.cache/node-gyp/5.0.7/include/node/node.h:560:36: note: in definition of macro ‘NODE_MODULE_X’ (node::addon_register_func) (regfunc),
^~~~~~~ ../src/node_printer.cc:19:1: note: in expansion of macro ‘NODE_MODULE’ NODE_MODULE(node_printer, initNode); ^~~~~~~~~~~ ../src/node_printer.cc:23:39: error: redefinition of ‘bool getStringOrBufferFromV8Value’ bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^~~~~~ In file included from ../src/node_printer.cc:1:0: ../src/node_printer.hpp:121:6: note: ‘bool getStringOrBufferFromV8Value’ previously defined here bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/node_printer.cc:23:39: error: ‘Handle’ is not a member of ‘v8’ bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^~~~~~ ../src/node_printer.cc:23:55: error: expected primary-expression before ‘>’ token bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^ ../src/node_printer.cc:23:57: error: ‘iV8Value’ was not declared in this scope bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^~~~~~~~ ../src/node_printer.cc:23:79: error: expected primary-expression before ‘&’ token bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^ ../src/node_printer.cc:23:80: error: ‘oData’ was not declared in this scope bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^~~~~ node_printer.target.mk:108: recipe for target 'Release/obj.target/node_printer/src/node_printer.o' failed make: *** [Release/obj.target/node_printer/src/node_printer.o] Error 1 make: Leaving directory '/home/df/Try/electron/pt-printer/node_modules/printer/build'

gyp ERR! build error gyp ERR! stack Error: make failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/home/df/.nvm/versions/node/v10.16.0/lib/node_modules/node-gyp/lib/build.js:196:23) gyp ERR! stack at ChildProcess.emit (events.js:198:13) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12) gyp ERR! System Linux 4.18.0-25-generic gyp ERR! command "/home/df/.nvm/versions/node/v10.16.0/bin/node" "/home/df/.nvm/versions/node/v10.16.0/bin/node-gyp" "rebuild" "--target=5.0.7" "--arch=x64" "--dist-url=https://electronjs.org/headers" gyp ERR! cwd /home/df/Try/electron/pt-printer/node_modules/printer gyp ERR! node -v v10.16.0 gyp ERR! node-gyp -v v5.0.3 gyp ERR! not ok`

My enviroment is ubuntu 18.04 with: yarn 1.17.3 node 10.16.0 electron 5.0.7

some help?

bayocr avatar Jul 23 '19 02:07 bayocr

Use electron rebuild instead. Search for full instructions in the electron docs

On Mon, Jul 22, 2019, 10:12 PM Dario Olazar [email protected] wrote:

@MikeVermilion https://github.com/MikeVermilion Hi, I'm trying to install, First i installed electron then printer, when i go to node_modules/printer folder and run: node-gyp rebuild --target=5.0.7 --arch=x64 --dist-url=https://electronjs.org/headers I get some warnings and these errors: `In file included from ../src/node_printer.cc:1:0: ../src/node_printer.hpp: At global scope: ../src/node_printer.hpp:121:39: error: ‘Handle’ is not a member of ‘v8’ bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^~~~~~ ../src/node_printer.hpp:121:55: error: expected primary-expression before ‘>’ token bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^ ../src/node_printer.hpp:121:57: error: ‘iV8Value’ was not declared in this scope bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^~~~~~~~ ../src/node_printer.hpp:121:79: error: expected primary-expression before ‘&’ token bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^ ../src/node_printer.hpp:121:80: error: ‘oData’ was not declared in this scope bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^~~~~ ../src/node_printer.hpp:121:85: error: expression list treated as compound expression in initializer [-fpermissive] bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^ ../src/node_printer.cc:5:19: error: variable or field ‘initNode’ declared void void initNode(v8::Handlev8::Object exports) { ^~~~~~ ../src/node_printer.cc:5:19: error: ‘Handle’ is not a member of ‘v8’ ../src/node_printer.cc:5:36: error: expected primary-expression before ‘>’ token void initNode(v8::Handlev8::Object exports) { ^ ../src/node_printer.cc:5:38: error: ‘exports’ was not declared in this scope void initNode(v8::Handlev8::Object exports) { ^~~~~~~ In file included from ../src/node_printer.hpp:6:0, from ../src/node_printer.cc:1: ../src/node_printer.cc:19:27: error: ‘initNode’ was not declared in this scope NODE_MODULE(node_printer, initNode); ^ /home/df/.cache/node-gyp/5.0.7/include/node/node.h:560:36: note: in definition of macro ‘NODE_MODULE_X’ (node::addon_register_func) (regfunc), ^~~~~~~ ../src/node_printer.cc:19:1: note: in expansion of macro ‘NODE_MODULE’ NODE_MODULE(node_printer, initNode); ^~~~~~~~~~~ ../src/node_printer.cc:19:27: note: suggested alternative: ‘initstate’ NODE_MODULE(node_printer, initNode); ^ /home/df/.cache/node-gyp/5.0.7/include/node/node.h:560:36: note: in definition of macro ‘NODE_MODULE_X’ (node::addon_register_func) (regfunc), ^~~~~~~ ../src/node_printer.cc:19:1: note: in expansion of macro ‘NODE_MODULE’ NODE_MODULE(node_printer, initNode); ^~~~~~~~~~~ ../src/node_printer.cc:23:39: error: redefinition of ‘bool getStringOrBufferFromV8Value’ bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^~~~~~ In file included from ../src/node_printer.cc:1:0: ../src/node_printer.hpp:121:6: note: ‘bool getStringOrBufferFromV8Value’ previously defined here bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/node_printer.cc:23:39: error: ‘Handle’ is not a member of ‘v8’ bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^~~~~~ ../src/node_printer.cc:23:55: error: expected primary-expression before ‘>’ token bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^ ../src/node_printer.cc:23:57: error: ‘iV8Value’ was not declared in this scope bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^~~~~~~~ ../src/node_printer.cc:23:79: error: expected primary-expression before ‘&’ token bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^ ../src/node_printer.cc:23:80: error: ‘oData’ was not declared in this scope bool getStringOrBufferFromV8Value(v8::Handlev8::Value iV8Value, std::string &oData) ^~~~~ node_printer.target.mk:108: recipe for target 'Release/obj.target/node_printer/src/node_printer.o' failed make: *** [Release/obj.target/node_printer/src/node_printer.o] Error 1 make: Leaving directory '/home/df/Try/electron/pt-printer/node_modules/printer/build'

gyp ERR! build error gyp ERR! stack Error: make failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/home/df/.nvm/versions/node/v10.16.0/lib/node_modules/node-gyp/lib/build.js:196:23) gyp ERR! stack at ChildProcess.emit (events.js:198:13) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12) gyp ERR! System Linux 4.18.0-25-generic gyp ERR! command "/home/df/.nvm/versions/node/v10.16.0/bin/node" "/home/df/.nvm/versions/node/v10.16.0/bin/node-gyp" "rebuild" "--target=5.0.7" "--arch=x64" "--dist-url=https://electronjs.org/headers" gyp ERR! cwd /home/df/Try/electron/pt-printer/node_modules/printer gyp ERR! node -v v10.16.0 gyp ERR! node-gyp -v v5.0.3 gyp ERR! not ok`

My enviroment is ubuntu 18.04 with: yarn 1.17.3 node 10.16.0 electron 5.0.7

some help?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tojocky/node-printer/issues/249?email_source=notifications&email_token=ABFU3KENXMEX4DI6HWIX7STQAZSI7A5CNFSM4HJAGGPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2RWLTI#issuecomment-514024909, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFU3KBWYBOX7JWLFSWUE3DQAZSI7ANCNFSM4HJAGGPA .

patrickrobbins avatar Jul 23 '19 02:07 patrickrobbins

@bayocr the error you are getting is because the v8 api changed in node 12 (or something like that), so this super important plugin needs to get updated. I’m not sure what @pattrickrobbins is suggesting about electron rebuild (I’d really like to get that working though), but he submitted a pull request where you can see the changes needed to use this plugin with node 12. I tried compiling his fork and it compiles. I could call getPrinters, but printDirect wasn’t working, because it wasn’t able to pass the printername and type variables correctly anymore. C++ is difficult because you have to convert from similar types with little documentation, so got to go figure this out. As soon as someone posts a working fork we can use that command I posted to build it. I might look at it more tonight if I have time.

MikeVermilion avatar Jul 23 '19 03:07 MikeVermilion

I have this project working now in electron 5.0.7 on Windows. I don't have time to test on Mac and Linux right now. Just make sure to tell npm to ignore scripts. npm i https://github.com/DatabaseWorks/node-printer --save --ignore-scripts

And here I'm telling it to build a 64bit version for electron 5.0.7 cd node_modules/printer node-gyp rebuild --target=5.0.7 --arch=x64 --dist-url=https://electronjs.org/headers

MikeVermilion avatar Jul 23 '19 07:07 MikeVermilion

@MikeVermilion Did you get the printing working in the latest version of Electron? I never used that feature so I didn't have code to test it in my local. I see that there are some changes in String::Utf8Value. I could take a look if you haven't already found a solution.

patrickrobbins avatar Jul 23 '19 19:07 patrickrobbins

Yes, it’s working on my fork, but I have to npm install it with the post install scripts disabled. The part of your code that wasn’t working for me was needed for those scripts to compile for some reason. I haven’t really spent much time trying to understand this as I have to roll out a project this week that needs to print.

MikeVermilion avatar Jul 23 '19 19:07 MikeVermilion

I have this project working now in electron 5.0.7 on Windows. I don't have time to test on Mac and Linux right now. Just make sure to tell npm to ignore scripts. npm i https://github.com/DatabaseWorks/node-printer --save --ignore-scripts

And here I'm telling it to build a 64bit version for electron 5.0.7 cd node_modules/printer node-gyp rebuild --target=5.0.7 --arch=x64 --dist-url=https://electronjs.org/headers

hi mike, i got error when use your repo

../src/node_printer_posix.cc:121:70: error: no viable conversion from 'v8::Isolate *' to 'Localv8::Context'

my env mac os node 12 electron 6.0.0-beta

triasbrata avatar Jul 24 '19 05:07 triasbrata

I’ll take a look.

MikeVermilion avatar Jul 24 '19 05:07 MikeVermilion

I got this compiling now, I'll check something in soon, when I've had time to review it a bit.

MikeVermilion avatar Jul 24 '19 19:07 MikeVermilion

@triasbrata, I updated my fork to compile for Mac and Windows now. Also note, that this probably will require running all these commands if someone checks out the project, since npm install will probably drop the module from the initial script failures. Maybe I need to remove some of the scripts that run on npm install. I don't spend a lot of time working in either node.js or C++, so this is taking me a bit to get up-to-speed.

npm i https://github.com/DatabaseWorks/node-printer --save --ignore-scripts cd node_modules/printer node-gyp configure node-gyp rebuild --target=5.0.7 --arch=x64 --dist-url=https://electronjs.org/headers

MikeVermilion avatar Jul 24 '19 22:07 MikeVermilion

More progress now, I cleared up even more build errors, so I no longer need the --ignore-scripts option when installing the plugin. I removed the node-pre-gyp stuff, because I have no intention of ever uploading binaries. I also added an npm script that I use along with electron-builder and it's now auto-building the node-printer for electron. Finally a good experience again. It now builds for the correct node.js version as was the point of this original issue and it also now builds for node 12.

You can npm install electron-builder and you add this to the npm scripts in the Package.json: "postinstall": "electron-builder install-app-deps"

Then: npm i https://github.com/DatabaseWorks/node-printer --save

Now it will install the printer plugin and build it with the correct version of node.js automatically.

MikeVermilion avatar Jul 25 '19 00:07 MikeVermilion

Great job. I was going to try to look into getting it set up, but you did it all!

On Wed, Jul 24, 2019, 8:52 PM Mike Vermilion [email protected] wrote:

More progress now, I cleared up even more build errors, so I no longer need the --ignore-scripts option when installing the plugin. I removed the node-pre-gyp stuff, because I have no intention of ever uploading binaries. I also added an npm script that I use along with electron-builder and it's now auto-building the node-printer for electron. Finally a good experience again. It now builds for the correct node.js version as was the point of this original issue and it also now builds for node 12.

You can npm install electron-builder and you add this to the Package.json: "postinstall": "electron-builder install-app-deps"

Then: npm i https://github.com/DatabaseWorks/node-printer --save

Now it will install the printer plugin and build it with the correct version of node.js automatically.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tojocky/node-printer/issues/249?email_source=notifications&email_token=ABFU3KEOMTQWXE4PPK2GEKTQBD2LLA5CNFSM4HJAGGPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2YAJFI#issuecomment-514851989, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFU3KB4JYI464FPDO3RYVLQBD2LLANCNFSM4HJAGGPA .

patrickrobbins avatar Jul 25 '19 03:07 patrickrobbins

More progress now, I cleared up even more build errors, so I no longer need the --ignore-scripts option when installing the plugin. I removed the node-pre-gyp stuff, because I have no intention of ever uploading binaries. I also added an npm script that I use along with electron-builder and it's now auto-building the node-printer for electron. Finally a good experience again. It now builds for the correct node.js version as was the point of this original issue and it also now builds for node 12.

You can npm install electron-builder and you add this to the npm scripts in the Package.json: "postinstall": "electron-builder install-app-deps"

Then: npm i https://github.com/DatabaseWorks/node-printer --save

Now it will install the printer plugin and build it with the correct version of node.js automatically.

wow great work dude

triasbrata avatar Jul 25 '19 15:07 triasbrata

yeah, work perfect great job

bayocr avatar Jul 25 '19 21:07 bayocr

Thanks everyone. If I get more time in a few days I will look at all the warnings and maybe clean this up and work towards getting a Pull Request put together. All the warnings have me worried about the near future, lol.

MikeVermilion avatar Jul 25 '19 22:07 MikeVermilion

Electron: v7.1.7 printer: npm i https://github.com/DatabaseWorks/node-printer --save MacOS: 10.15.2

Hey guys, I have been pulling my hair on this and I actually tried @MikeVermilion solution. I added electron-builder as dev dep, added a "postinstall": "electron-builder install-app-deps" into Package.json->scripts section and then ran npm i https://github.com/DatabaseWorks/node-printer --save. I started my electron app and this still shows up:

Uncaught Error: Cannot open /Users/simanto_r/Projects/POS-X/POS Terminal/node_modules/printer/lib/node_printer.node: Error: The module '/Users/simanto_r/Projects/POS-X/POS Terminal/node_modules/printer/lib/node_printer.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 57. This version of Node.js requires
NODE_MODULE_VERSION 75. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.eval (node_printer.node:1)
    at eval (node_printer.node:2)
    at Object../node_modules/printer/lib/node_printer.node (bundle.js:347)
    at __webpack_require__ (bundle.js:20)
    at Object.eval (printer.js:9)
    at eval (printer.js:333)
    at Object../node_modules/printer/lib/printer.js (bundle.js:358)
    at __webpack_require__ (bundle.js:20)
    at eval (App.tsx:59)
    at Object../src/App.tsx (bundle.js:784)

SimantoR avatar Dec 20 '19 21:12 SimantoR

I haven't tried to build this in almost 6 months, but below is what I had in my package.json related to this. You're problem is somehow you're trying to use the pre-compiled binaries made with node-pre-gyp that shipped with the plugin. That's probably why it says the node module versions don't match. You need to build them fresh with the same version of node.js that electron is using. You can rebuild the module if necessary, but electron builder has the ability to do this automatically. The post install line is documented in the npm website for electron-builder, but you can build it manually yourself, which is a bit more effort...

To do it manually is like this, where the target is your electron version. cd node_modules/printer node-gyp configure node-gyp rebuild --target=5.0.7 --arch=x64 --dist-url=https://electronjs.org/headers

This is how I have my package.json setup... "scripts": { "postinstall": "electron-builder install-app-deps", "start": "electron . --enable-logging", "dev": "set NODE_ENV='development' npm run start", "dist": "electron-builder --mac dmg --win nsis --x64", "dist-win": "electron-builder --win nsis --x64" }, "devDependencies": { "electron": "5.0.7", "electron-builder": "21.1.1", "electron-builder-squirrel-windows": "21.1.6" }, "dependencies": { "printer": "git+https://github.com/DatabaseWorks/node-printer.git" },

For some more reading material see the following article discussing the building of native modules for electron and the issues involved. https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md

MikeVermilion avatar Dec 20 '19 21:12 MikeVermilion