how to build python with node-gyp? - javascript

I've seen the official tutorial as well as this one showing how to build python from source and edit it with visual studio etc., but how do I build it with node-gyp to use it as a native application in node?
For example, in the tutorial, they tell you to download the source code, and then (in windows) type in that directory:
"PCbuild/build.bat"
and then that builds the Visual Studio solution and python in general etc., but now how do I do that with node-gyp? In general, to include external dependencies to build with node-gyp, you just include them in the binding.gyp file. For python, I first installed 64 bit (and later 32 bit, same error as below) python to C:/Python382, then I copied that folder to my another folder in my C++ application, and set the binding.gyp file to this (to get the include and libs):
{
"targets": [
{
"target_name": "addon",
"sources": [
"<!#(node -p \"var fs=require('fs'),path=require('path'),walk=function(r){let t,e=[],n=null;try{t=fs.readdirSync(r)}catch(r){n=r.toString()}if(n)return n;var a=0;return function n(){var i=t[a++];if(!i)return e;let u=path.resolve(r,i);i=r+'/'+i;let c=fs.statSync(u);if(c&&c.isDirectory()){let r=walk(i);return e=e.concat(r),n()}return e.push(i),n()}()};walk('./sources').join(' ');\")"
],
"libraries":[
"C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/libs/python38.lib",
"C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/libs/python3.lib",
"C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/libs/_tkinter.lib"
],
"include_dirs": [
"C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/include"
],
"dll_files": [
"C:/Users/Coby/Documents/aa/atzmus/CPPtesting/other/ok/Python382/python38.dll"
]
}
]
}
and my hello.cc file, which is the other source, simply includes Python.h. When I run this build using node-gyp build or node-gyp rebuild, it actually builds fine with no errors at all, but then when I copy over the file addon.node to my actual nodeJS server, which simply has the one line var addon = require("./addon"), I get the following error output in CMD (however, it works fine with no errors without including Python.h in my .cc source file):
internal/modules/cjs/loader.js:1197
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: \\?\C:\Users\Coby\Documents\aa\atzmus\testServer\addon.node is not a valid Win32 application.
\\?\C:\Users\Coby\Documents\aa\atzmus\testServer\addon.node
←[90m at Object.Module._extensions..node (internal/modules/cjs/loader.js:1197
:18)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:983:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:891:14)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:1023:19)←[39m
←[90m at require (internal/modules/cjs/helpers.js:72:18)←[39m
at Object.<anonymous> (C:\Users\Coby\Documents\aa\atzmus\testServer\oy.js:2:
9)
←[90m at Module._compile (internal/modules/cjs/loader.js:1128:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:1
0)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:983:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:891:14)←[39m
The main part seems to be:
addon.node is not a valid Win32 application.
I tried doing this with python for 64bit windows, and for 32bit windows, my system in 64 bit, my nodeJS installation is 64 bit, but I also tried it with 32 bit note; I don't know how to fix this exactly, or if there is another way entirely to build python with node-gyp?
so:
What steps need to be taken in windows to build python through node-gyp, to be able to use python natively with nodejs without having to resort to child-process?

Related

nest.js error when deploying start:prod to Digital Ocean App Platform

I have been trying to deploy my app to DO and I keep getting the error
Error: Cannot find module '/workspace/dist/main'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Function.Module._load (node:internal/modules/cjs/loader:841:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
So I have tried different variations in the package.json within the start:prod command but cant get it to build complete
/
/dist/main
../dist/main
Does anyone have any experience with getting this to work?
start:prod sounds like it should be set to node dist/src/main. This usually is the case when there is a file from outside of src being compiled with src, and Typescript is maintaining the directory structure in the output directory.

Error while running an exe compiled with PKG

im compiling a file with PKG. But whenever I try to run the file it gives this error.
Error
All versions are up to date.
I'm trying to run my simple javascript code on another computer and this error pops up.
Error: Cannot find module 'C:\snapshot\highu\OneDrive\Masaüstü\XXX\node_modules\sqlite3\lib\binding\napi-v6-win32-unknown-x64\node_sqlite3.node'
Require stack:
- C:\snapshot\highu\OneDrive\Masaüstü\XXX\node_modules\sqlite3\lib\sqlite3-binding.js
- C:\snapshot\highu\OneDrive\Masaüstü\XXX\node_modules\sqlite3\lib\sqlite3.js
- C:\snapshot\highu\OneDrive\Masaüstü\XXX\.\.\.\.\.js
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Module._resolveFilename (node:internal/modules/cjs/loader:946:15)
at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
at Module._load (node:internal/modules/cjs/loader:787:27)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at Module.require (pkg/prelude/bootstrap.js:1855:31)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\snapshot\highu\OneDrive\Masaüstü\XXX\node_modules\sqlite3\lib\sqlite3-binding.js:4:17)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
at Module.load (node:internal/modules/cjs/loader:988:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\snapshot\\highu\\OneDrive\\Masaüstü\\XXX\\node_modules\\sqlite3\\lib\\sqlite3-binding.js',
'C:\\snapshot\\highu\\OneDrive\\Masaüstü\\XXX\\node_modules\\sqlite3\\lib\\sqlite3.js',
'C:\\snapshot\\highu\\OneDrive\\Masaüstü\\XXX\\.\\.\\.\\.\\.js'
],
pkg: true
}
Node.js v18.5.0

Issues installing Sequelize

I am finishing some backend tutorials and when i tried to install Sequelize with Node this is what it displays on the screen i have tried to downgrade the versions of Node js to solve the problem and updated other dependencies but it doesnt work, i am currently using 8.4.0 Node version, the one that is used on the tutorial and the lesson but it doesnt fix the issue, hope you can help me with this so i can move on to finish my course and do the exam, here it is what i get after trying to install:
P.D. I am working on a OS Windows 10 desktop computer.
C:\Users\AIO 330-20AST\Desktop\backend\base_datos> node server.js
node-pre-gyp info This Node instance does not support builds for N-API version 3
node-pre-gyp info This Node instance does not support builds for N-API version 6
C:\Users\AIO 330-20AST\Desktop\backend\base_datos\node_modules\node-pre-gyp\lib\util\napi.js:84
throw new Error(
^
Error: The N-API version of this Node instance is 1. This module
supports N-API version(s) 3,6. This Node instance cannot run this
module.
at Object.module.exports.validate_package_json (C:\Users\AIO
330-20AST\Desktop\backend\base_datos\node_modules\node-pre-gyp\lib\util\napi.js:84:9)
at Object.validate_config (C:\Users\AIO
330-20AST\Desktop\backend\base_datos\node_modules\node-pre-gyp\lib\util\versioning.js:229:10)
at Object.exports.find (C:\Users\AIO
330-20AST\Desktop\backend\base_datos\node_modules\node-pre-gyp\lib\pre-binding.js:21:15)
at Object.<anonymous> (C:\Users\AIO
330-20AST\Desktop\backend\base_datos\node_modules\sqlite3\lib\sqlite3-binding.js:3:27)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
C:\Users\AIO 330-20AST\Desktop\backend\base_datos>
For your help thanks in advance, good coding!

Grave (`) is marked as illegal token

I've been trying to transfer a node program I created locally to an EC2 server via Cloud9, and I have already manually replaced all of the (req,res) => {} statements because it didn't accept that. However, now it's giving me
console.log(`foo ${bar}`)
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:945:3
It works fine on my local server and it runs fine here too, even without nodejs.
var bar = "bar"
console.log(`foo ${bar}`)
The version of node is v13.9.0 and it was installed via nvp.
Anyone know why this is happening? I really don't want to go through and convert all the strings with `
Thanks for the help, I figured out that cloud9 automatically installs nodejs, just not the right version. It installs 10.19.0, while the current latest version is 13.10.0. I installed the latest version, but the default was still 10.19.0. For anyone else having this problem, do
nvm ls
to list your installed node versions, then use
nvm alias default 13.10.0 (replace with whatever version you want)

react-native-fetch-blob link FAILED

How can i Fix my error. i need to display a pdf from my assets folder. im using expo, react native, react-native-pdf
Scanning folders for symlinks in C:\Users\kjdelacruz\mobile\cdo-mobile-organizer\node_modules (31ms)
RNFetchBlob checking app version ..
RNFetchBlob detected app version => 6
Add Android permissions => false
react-native-fetch-blob link FAILED
Could not automatically link package :TypeError: path must be a string or Buffer
at Object.fs.readFile (fs.js:358:11)
at Object.<anonymous> (C:\Users\kjdelacruz\mobile\cdo-mobile-organizer\node_modules\react-native-fetch-blob\scripts\prelink.js:29:8)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3please follow the instructions to manually link the library : https://github.com/wkh237/react-native-fetch-blob/wiki/Manually-Link-Package
rnpm-install info Linking assets to ios project
rnpm-install ERR! Something went wrong while linking. Error: Cannot read property 'pbxprojPath' of null
Please file an issue here: https://github.com/facebook/react-native/issues
Cannot read property 'pbxprojPath' of null
Apparently rn-fetch-blob is incompatible with expo. I have dealt with this very problem before with expo and rn-fetch-blob.
"It doesn't work with Expo because Expo doesn't support native module linking. Like you said you'll have to detach from Expo in order to run react-native link react-native-fetch-blob for this to work."
https://docs.expo.io/versions/latest/guides/detach.html
You will need to use XCode to get it working.
There are a couple threads discussing. No solutions with expo though.
https://github.com/joltup/rn-fetch-blob/issues/97
https://github.com/wkh237/react-native-fetch-blob/issues/371

Categories