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

Failed compilation - "No such file or directory @ rb_sysopen"

Open gillez opened this issue 7 years ago • 7 comments

Hi,

I'm trying to compile my node app on MacOS v10.11.6. It fails with the following error:

-> cp "/var/folders/kz/vj4tms290qq_04ylv6p54ks40000gq/T/nodec/node/out/Release/node" "nodec_output/app"
/__enclose_io_memfs__/_global_/lib/ruby/2.4.0/fileutils.rb:1289:in `initialize': No such file or directory @ rb_sysopen - nodec_output/app (Errno::ENOENT)
	from /__enclose_io_memfs__/_global_/lib/ruby/2.4.0/fileutils.rb:1289:in `open'
	from /__enclose_io_memfs__/_global_/lib/ruby/2.4.0/fileutils.rb:1289:in `block in copy_file'
	from /__enclose_io_memfs__/_global_/lib/ruby/2.4.0/fileutils.rb:1288:in `open'
	from /__enclose_io_memfs__/_global_/lib/ruby/2.4.0/fileutils.rb:1288:in `copy_file'
	from /__enclose_io_memfs__/_global_/lib/ruby/2.4.0/fileutils.rb:429:in `copy_file'
	from /__enclose_io_memfs__/_global_/lib/ruby/2.4.0/fileutils.rb:356:in `block in cp'
	from /__enclose_io_memfs__/_global_/lib/ruby/2.4.0/fileutils.rb:1460:in `block in fu_each_src_dest'
	from /__enclose_io_memfs__/_global_/lib/ruby/2.4.0/fileutils.rb:1476:in `fu_each_src_dest0'
	from /__enclose_io_memfs__/_global_/lib/ruby/2.4.0/fileutils.rb:1458:in `fu_each_src_dest'
	from /__enclose_io_memfs__/_global_/lib/ruby/2.4.0/fileutils.rb:355:in `cp'
	from /__enclose_io_memfs__/_local_/lib/compiler/utils.rb:39:in `cp'
	from /__enclose_io_memfs__/_local_/lib/compiler.rb:250:in `compile_mac'
	from /__enclose_io_memfs__/_local_/lib/compiler.rb:141:in `run!'
	from /__enclose_io_memfs__/_local_/bin/nodec:123:in `<main>'

I don't use ruby or rb_sysopen directly in my code, but I guess it's possible that one of the included npm modules do (although a grep in the node_modules directory for rb_sysopen drew a blank).

I am using the following version: Node.js Compiler (nodec) v0.9.6 (runtime 7.10.0)

Can anyone help with this?

Thanks, Giles

gillez avatar May 15 '17 14:05 gillez

Hi Giles,

Thanks for reporting. It's me who used rb_sysopen. 😝 Node.js Compiler is written using Ruby.

Based on the output it seems not like a big problem. The error happened at the very last step when the compiler is copying the final product from /var/folders/kz/vj4tms290qq_04ylv6p54ks40000gq/T/nodec/node/out/Release/node to nodec_output/app when it found out that the directory nodec_output does not exist.

Did you use nodec with the argument -o nodec_output/app or --output=nodec_output/app? If so you need to first create the directory nodec_output. Please let me know if it works. Thanks.

pmq20 avatar May 16 '17 03:05 pmq20

Hi Minqi,

Thanks for the reply. After creating the output directory and rerunning, the situation has improved. It now compiles and I get an output file.

However, when running this app (it's a web server that uses couchbase) I get an error:

Error: dlopen(/__enclose_io_memfs__/node_modules/couchbase/build/Release/couchbase_impl.node, 1): image not found

This file is in the node_modules/couchbase tree. How do I package this in the output, or point to it as an external file? The readme does not make this clear.

I also made a cut down version of the app that doesn't use couchbase. This compiled and ran, but when trying to access the web index.html page, it can't find this. I guess it's going to be the same problem - how do I package the html file in the executable, or access it externally?

Thanks, Giles

gillez avatar May 16 '17 11:05 gillez

@gillez Thanks for the feedback. For the first problem, it's related to #29, #25 and #27 and has been fixed yet not released. Native modules are starting to work on the master branch, if you are urgent you could clone the repo and run nodec from master to try it. I'll release it once I have tested it thoroughly.

For the second problem, I am not quite sure what you are referring to that is missing. Could you give me more details? What do you mean by "it can't find this"? Thank you.

pmq20 avatar May 17 '17 03:05 pmq20

Hi Minqi,

Sorry for the lack of details on the second issue. Here's some more info: My node app runs a web server, delivering files through express. When a request comes in for the home page I call the following:

res.sendFile(i"index.html", { root: __dirname + "/public/dist"});

This works perfectly when starting the server directly through node. However, when running the nodec compiled app, this call gives the following error:

Error: ENOENT: no such file or directory, stat '/public/dist/index.html'

I guess this is because the "__dirname" variable does not have a valid value? What should I use here?

I have also compiled my app using pkg which is working. In that case I have to list my html files (and other files for the website, such as JS and images) as assets, which are then packaged into the single-file executable. There are no code changes and my website is delivered correctly. Do I need to do a similar thing with node compiler?

As an aside, the only files which are not packaged into the single-file with pkg are native modules such as couchbase_impl.node. Those need to be supplied separately, in the same directory as the pkg output. I have tried the same thing with the nodec output, thinking it would solve my first issue but it didn't help.

Thanks, Giles

gillez avatar May 17 '17 08:05 gillez

Hi Minqi,

Do you have any more info on my second issue above? I'd like to know how to package my html/js files for the client website inside the node app, or whether this should be done another way. I'm sure it's just me doing something silly or not specifying the assets or something.

Thanks, Giles

gillez avatar May 25 '17 11:05 gillez

Hi Giles,

Sorry for the delay. I've been working busily towards nodec v1.0 recently.

Regarding __dirname, it really should not output an empty string. If the code res.sendFile(i"index.html", { root: __dirname + "/public/dist"}) is inside your project, say at project_root/a/b.js then __dirname should be project_root/a before compiling and become __encloes_io_memfs__/a after compiling, which should work with public/dist as long as they are all under your project_root.

Therefore this is either a bug in nodec, or the code res.sendFile(i"index.html", { root: __dirname + "/public/dist"}) reside outside your project. Could you help me reproduce it on my machine so I can fix it? A reduced set of code that could reproduce the issue would suffice. Thank you very much.

Minqi

pmq20 avatar May 26 '17 03:05 pmq20

Thanks Minqi,

Actually I think that explains it. The public directory is actually a sub directory of the parent of my app. My real code is more like __dirname + "../public/dist" I'll try moving my top level application file to the parent directory and building from there. From your explanation, I feel confident that will fix it.

I'll update this thread to let you know when I've tried it.

Cheers, Giles

gillez avatar May 26 '17 15:05 gillez