New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native modules support #12

Closed
robinrodricks opened this Issue Mar 16, 2015 · 14 comments

Comments

Projects
None yet
6 participants
@robinrodricks
Contributor

robinrodricks commented Mar 16, 2015

Does enclose support native modules? Can it be packaged along with the executable or is it not supported at all?

@igorklopov

This comment has been minimized.

Show comment
Hide comment
@igorklopov

igorklopov Mar 16, 2015

Owner

Enclose cannot package a native module inside executable. But it supports if you distribute a native module near the executable and require that native module at runtime. You may try serialport example: https://github.com/igorklopov/enclose/tree/master/examples/44-serialport

Owner

igorklopov commented Mar 16, 2015

Enclose cannot package a native module inside executable. But it supports if you distribute a native module near the executable and require that native module at runtime. You may try serialport example: https://github.com/igorklopov/enclose/tree/master/examples/44-serialport

@igorklopov

This comment has been minimized.

Show comment
Hide comment
@igorklopov

igorklopov Mar 16, 2015

Owner

Btw, enclose supports if you require pure node modules without recompilation. I mean you can use stock node-gyp and this issue electron/electron#713 will not bother you in enclose

Owner

igorklopov commented Mar 16, 2015

Btw, enclose supports if you require pure node modules without recompilation. I mean you can use stock node-gyp and this issue electron/electron#713 will not bother you in enclose

@robinrodricks

This comment has been minimized.

Show comment
Hide comment
@robinrodricks

robinrodricks Mar 17, 2015

Contributor

Thats great! I'll try it out and let you know. Thanks for building this project!!

Contributor

robinrodricks commented Mar 17, 2015

Thats great! I'll try it out and let you know. Thanks for building this project!!

@robinrodricks

This comment has been minimized.

Show comment
Hide comment
@robinrodricks

robinrodricks Mar 17, 2015

Contributor

I'm getting some errors while packaging my app with enclose. I have compile.js, my index.js and couple of .node native module files in the same folder.

The .node binary files are built with node version 0.8.xx, and I have node version 0.8.xx installed.

My main code file index.js uses the node files with the following statements

var a = require('./a');
var b = require('./b');

(a.node and b.node are the native modules.)

For compile.js I have modified your serial port example:

try {
  require.resolve("./a");
} catch(error) {
  console.log("Failed to require('a')");
  console.log("Please run 'npm install' here");
  process.exit(1);
}

(and similar lines for module b.node)

The error:

{ was_required_as: './a',
file: 'D:\enclose\examples\test\index.js'
,
directory: 'D:\enclose\examples\test' }
undefined:0

Error: Cannot find module './a' from 'D:\enclose\examples\test'
at
at load ()
at
at
at FSReqWrap.oncomplete (fs.js:99:15)

Contributor

robinrodricks commented Mar 17, 2015

I'm getting some errors while packaging my app with enclose. I have compile.js, my index.js and couple of .node native module files in the same folder.

The .node binary files are built with node version 0.8.xx, and I have node version 0.8.xx installed.

My main code file index.js uses the node files with the following statements

var a = require('./a');
var b = require('./b');

(a.node and b.node are the native modules.)

For compile.js I have modified your serial port example:

try {
  require.resolve("./a");
} catch(error) {
  console.log("Failed to require('a')");
  console.log("Please run 'npm install' here");
  process.exit(1);
}

(and similar lines for module b.node)

The error:

{ was_required_as: './a',
file: 'D:\enclose\examples\test\index.js'
,
directory: 'D:\enclose\examples\test' }
undefined:0

Error: Cannot find module './a' from 'D:\enclose\examples\test'
at
at load ()
at
at
at FSReqWrap.oncomplete (fs.js:99:15)

@igorklopov

This comment has been minimized.

Show comment
Hide comment
@igorklopov

igorklopov Mar 17, 2015

Owner

Unfortunately 0.8.x is too outdated to support. EncloseJS is similar to node 0.12 or (you can switch) iojs runtime environment. It means only modules compiled against 0.12 (or iojs) are compatible with EncloseJS. ALSO i see was_required_as - it old output format. Seems that you use outdated EncloseJS too. Please run npm update enclose

Owner

igorklopov commented Mar 17, 2015

Unfortunately 0.8.x is too outdated to support. EncloseJS is similar to node 0.12 or (you can switch) iojs runtime environment. It means only modules compiled against 0.12 (or iojs) are compatible with EncloseJS. ALSO i see was_required_as - it old output format. Seems that you use outdated EncloseJS too. Please run npm update enclose

@robinrodricks

This comment has been minimized.

Show comment
Hide comment
@robinrodricks

robinrodricks Mar 19, 2015

Contributor

Thanks, I'll compile my modules for Node 0.12 and get back to you. Just for anyone reading this thread, I'm having trouble porting my native module from 0.8 to 0.12 so I'm using NAN to simplify the porting process.

NAN is the Native Abstraction layer for Node, and provides a set of C++ templates that enables you to compile for newer node versions WITHOUT changing your module source code, because they have tackled the inconsistencies and changes within the templates.

https://github.com/rvagg/nan

Contributor

robinrodricks commented Mar 19, 2015

Thanks, I'll compile my modules for Node 0.12 and get back to you. Just for anyone reading this thread, I'm having trouble porting my native module from 0.8 to 0.12 so I'm using NAN to simplify the porting process.

NAN is the Native Abstraction layer for Node, and provides a set of C++ templates that enables you to compile for newer node versions WITHOUT changing your module source code, because they have tackled the inconsistencies and changes within the templates.

https://github.com/rvagg/nan

@robinrodricks

This comment has been minimized.

Show comment
Hide comment
@robinrodricks

robinrodricks Mar 20, 2015

Contributor

I managed to make native modules work with encloseJS. Great job!

  • I downloaded the latest encloseJS
  • I compiled all modules for Node 0.12
  • I placed .node files in same dir as compiled executable

Only issue is that when I run the app, it creates a copy of the .node files.
Eg: Suppose we have utils.node, it creates utils.MYSERVER.exe.node, which is a copy of the node file. Why does it create this copy?

Contributor

robinrodricks commented Mar 20, 2015

I managed to make native modules work with encloseJS. Great job!

  • I downloaded the latest encloseJS
  • I compiled all modules for Node 0.12
  • I placed .node files in same dir as compiled executable

Only issue is that when I run the app, it creates a copy of the .node files.
Eg: Suppose we have utils.node, it creates utils.MYSERVER.exe.node, which is a copy of the node file. Why does it create this copy?

@igorklopov

This comment has been minimized.

Show comment
Hide comment
@igorklopov

igorklopov Mar 20, 2015

Owner

It is not a copy. If you compare, you will see differences. There is a problem with node native modules in win32 - they require executable name to be 'node.exe'. EncloseJS patches the IAT of native module before dlopen and binds it to 'myserver.exe'. And the patched module is placed near original one. If you dont like it, rename/replace original utils.node with utils.myserver.exe.node - EncloseJS will detect it is already patched and dont create a new file.

Owner

igorklopov commented Mar 20, 2015

It is not a copy. If you compare, you will see differences. There is a problem with node native modules in win32 - they require executable name to be 'node.exe'. EncloseJS patches the IAT of native module before dlopen and binds it to 'myserver.exe'. And the patched module is placed near original one. If you dont like it, rename/replace original utils.node with utils.myserver.exe.node - EncloseJS will detect it is already patched and dont create a new file.

@robinrodricks

This comment has been minimized.

Show comment
Hide comment
@robinrodricks

robinrodricks Mar 20, 2015

Contributor

Fantastic! You have put so many advanced features into EncloseJS. Great job.

Contributor

robinrodricks commented Mar 20, 2015

Fantastic! You have put so many advanced features into EncloseJS. Great job.

@serkanp

This comment has been minimized.

Show comment
Hide comment
@serkanp

serkanp Apr 26, 2015

i have problem with native modules.. such as sqlite3
my app.js:
var fs=require('fs')
var path=require('path')
console.log(path.resolve(__dirname))
var moment=require('moment')
console.log(moment().format())
console.log('try loading sqlite3')
try {
require.resolve("sqlite3");
} catch(error) {
console.log("Failed to require('sqlite3')");
console.log("Please run 'npm install' here");
process.exit(1);
}

console.log('seems sqlite can be loaded')

var sqlite=require('sqlite3')

my package.json:
{
"name": "deneme",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"moment": "^2.10.2",
"sqlite3": "^3.0.5"
},
"devDependencies": {
"moment": "^2.10.2",
"sqlite3": "^3.0.5"
},
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC"
}

enclose output:
E:\deneme>enclose --x64 app.js

e:\deneme\node_modules\sqlite3\lib\sqlite3.js
warning Cannot resolve 'require(binding_path)'
Use a string literal as argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option

e:\deneme\node_modules\moment\moment.js
warning Cannot resolve 'require('./locale/' + name)'
Use a string literal as argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option

e:\deneme\node_modules\sqlite3\node_modules\node-pre-gyp\lib\node-pre-gyp.js
warning Cannot resolve 'require('./' + command)'
Use a string literal as argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option

e:\deneme\node_modules\sqlite3\node_modules\node-pre-gyp\lib\node-pre-gyp.js
warning Cannot resolve 'require('./' + c)'
Use a string literal as argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option

e:\deneme\node_modules\sqlite3\node_modules\node-pre-gyp\lib\pre-binding.js
warning Cannot resolve 'require(package_json_path)'
Use a string literal as argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option

i get this when i run app.exe:
E:\deneme>app.exe
e:\thebox\deneme
2015-04-26T23:26:47+03:00
try loading sqlite3
seems sqlite can be loaded
undefined:0

Error: Cannot find module 'e:\thebox\deneme\node_modules\sqlite3\lib\binding\nod
e-v14-win32-x64\node_sqlite3.node'
at Error (native)
at O ()
at c ()
at Object.Math.Enclose.+e+:++t+h+e+b+o+x++d+e+n+e+m+e++n+o+d+e+_+m+o+d+u+
l+e+s++s+q+l+i+t+e+3++l+i+b++s+q+l+i+t+e+3+.+j+s.dev ()
at u ()
at O ()
at c ()
at Object.Math.Enclose.+e+:++t+h+e+b+o+x++d+e+n+e+m+e++a+p+p+.+j+s.dev (<
anonymous>)
at u ()
at

serkanp commented Apr 26, 2015

i have problem with native modules.. such as sqlite3
my app.js:
var fs=require('fs')
var path=require('path')
console.log(path.resolve(__dirname))
var moment=require('moment')
console.log(moment().format())
console.log('try loading sqlite3')
try {
require.resolve("sqlite3");
} catch(error) {
console.log("Failed to require('sqlite3')");
console.log("Please run 'npm install' here");
process.exit(1);
}

console.log('seems sqlite can be loaded')

var sqlite=require('sqlite3')

my package.json:
{
"name": "deneme",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"moment": "^2.10.2",
"sqlite3": "^3.0.5"
},
"devDependencies": {
"moment": "^2.10.2",
"sqlite3": "^3.0.5"
},
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC"
}

enclose output:
E:\deneme>enclose --x64 app.js

e:\deneme\node_modules\sqlite3\lib\sqlite3.js
warning Cannot resolve 'require(binding_path)'
Use a string literal as argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option

e:\deneme\node_modules\moment\moment.js
warning Cannot resolve 'require('./locale/' + name)'
Use a string literal as argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option

e:\deneme\node_modules\sqlite3\node_modules\node-pre-gyp\lib\node-pre-gyp.js
warning Cannot resolve 'require('./' + command)'
Use a string literal as argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option

e:\deneme\node_modules\sqlite3\node_modules\node-pre-gyp\lib\node-pre-gyp.js
warning Cannot resolve 'require('./' + c)'
Use a string literal as argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option

e:\deneme\node_modules\sqlite3\node_modules\node-pre-gyp\lib\pre-binding.js
warning Cannot resolve 'require(package_json_path)'
Use a string literal as argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option

i get this when i run app.exe:
E:\deneme>app.exe
e:\thebox\deneme
2015-04-26T23:26:47+03:00
try loading sqlite3
seems sqlite can be loaded
undefined:0

Error: Cannot find module 'e:\thebox\deneme\node_modules\sqlite3\lib\binding\nod
e-v14-win32-x64\node_sqlite3.node'
at Error (native)
at O ()
at c ()
at Object.Math.Enclose.+e+:++t+h+e+b+o+x++d+e+n+e+m+e++n+o+d+e+_+m+o+d+u+
l+e+s++s+q+l+i+t+e+3++l+i+b++s+q+l+i+t+e+3+.+j+s.dev ()
at u ()
at O ()
at c ()
at Object.Math.Enclose.+e+:++t+h+e+b+o+x++d+e+n+e+m+e++a+p+p+.+j+s.dev (<
anonymous>)
at u ()
at

@jlEMEE

This comment has been minimized.

Show comment
Hide comment
@jlEMEE

jlEMEE Nov 17, 2015

Great idea !
I got that issue :
any idea ?

image

jlEMEE commented Nov 17, 2015

Great idea !
I got that issue :
any idea ?

image

@Bambofy

This comment has been minimized.

Show comment
Hide comment
@Bambofy

Bambofy Jan 3, 2016

Hello, I ran into a similar problem of it reporting that it needs updating when trying to enclose my scripts.

2016-01-03_01-56-34

Any ideas?

(ran enclose on a fresh install from npm)

Bambofy commented Jan 3, 2016

Hello, I ran into a similar problem of it reporting that it needs updating when trying to enclose my scripts.

2016-01-03_01-56-34

Any ideas?

(ran enclose on a fresh install from npm)

@AmitRaj07

This comment has been minimized.

Show comment
Hide comment
@AmitRaj07

AmitRaj07 Dec 2, 2016

My team has made a server application, which is running on RHEL6. We run this application in the development environment through the clear source code file (like main.js etc.) and we are also using the bcrypt module in this application. But my management has decided not to put source code in production, they wanted to put an executable (compiled version of the code) on production, so that an unauthorised person cannot see the code or do some malfunction activity.

Is it a good way to put executable (compiled version of the code) of a Node.js application or it will be better if we put source code in production?

My team has made a server application, which is running on RHEL6. We run this application in the development environment through the clear source code file (like main.js etc.) and we are also using the bcrypt module in this application. But my management has decided not to put source code in production, they wanted to put an executable (compiled version of the code) on production, so that an unauthorised person cannot see the code or do some malfunction activity.

Is it a good way to put executable (compiled version of the code) of a Node.js application or it will be better if we put source code in production?

@igorklopov

This comment has been minimized.

Show comment
Hide comment
@igorklopov

igorklopov May 3, 2017

Owner

Dear users of EncloseJS. I highly encourage you to switch to https://github.com/zeit/pkg
It is rewritten successor of EncloseJS. It is open source, and all improvements will go there.
Please check if pkg has your issue unresolved, and if it is true, reopen your issue there:
https://github.com/zeit/pkg/issues

Owner

igorklopov commented May 3, 2017

Dear users of EncloseJS. I highly encourage you to switch to https://github.com/zeit/pkg
It is rewritten successor of EncloseJS. It is open source, and all improvements will go there.
Please check if pkg has your issue unresolved, and if it is true, reopen your issue there:
https://github.com/zeit/pkg/issues

@igorklopov igorklopov reopened this May 3, 2017

@igorklopov igorklopov closed this May 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment