nexe: Bundled exe doesnt work without node_modules present in the same folder
Hello. I’m currently trying to bundle a simple script to list keys/values in the windows registry. For this i use the NPM ‘regedit’, however it seems to fail when packaged with nexe and I’m unsure if it’s something I’m doing wrong or not since this is the first time I’m using Nexe.
The error it’s outputting is:
events.js:174
throw er; // Unhandled 'error' event
^
SyntaxError: Unexpected token I in JSON at position 0
at JSON.parse (<anonymous>)
at DestroyableTransform.module.exports.vbsOutputTransform [as _transform] (C:\snapshot\Registry Cleanup\node_modules\regedit\lib\helper.js:51:18)
at DestroyableTransform.Transform._read (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:172:12)
at doWrite (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:237:10)
at writeOrBuffer (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:227:5)
at DestroyableTransform.Writable.write (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:194:11)
at StreamSlicer.ondata (_stream_readable.js:689:20)
at StreamSlicer.emit (events.js:189:13)
at addChunk (_stream_readable.js:284:12)
Emitted 'error' event at:
at DestroyableTransform.onerror (_stream_readable.js:713:12)
at DestroyableTransform.emit (events.js:189:13)
at onwriteError (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:250:10)
at onwrite (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:268:5)
at WritableState.onwrite (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:106:5)
at afterTransform (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:104:5)
at TransformState.afterTransform (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:79:12)
at DestroyableTransform.module.exports.vbsOutputTransform [as _transform] (C:\snapshot\Registry Cleanup\node_modules\regedit\lib\helper.js:53:10)
at DestroyableTransform.Transform._read (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (C:\snapshot\Registry Cleanup\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:172:12)
What you expected to happen: After bundling main.js, running the bundles exe file should list the values and keys at the given registry path.
How to reproduce it (as minimally and precisely as possible):
nexe main.js --build
main.js:
const regedit = require('regedit')
regedit.list("HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Devices")
.on('data', function(entry) {
const values = entry.data.values;
console.log('Values found: ', values)
})
.on('finish', function() {
console.log('finished')
})
Anything else we need to know?: The .exe file works if node_modules with regedit installed is present in the same folder as the .exe file.
Environment
- Platform(OS/Version): Windows 10 build 1803
- Host Node Version: v11.11.0
- Target Node Version: v11.11.0
- Nexe version: v3.2.1
- Python Version: v2.7.15
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (4 by maintainers)
Are there packages in particular that are failing to load?
One could use ncc to provide a bundle to nexe. Any other dist artifacts produced there (eg native modules) will have to be shipped alongside the binary)
I had the same issue and finally realized it was because I’ve used a child process with more required modules inside that JS file.
@timrspratt Thanks for the info.
@oonqt I don’t know of a way to load a library not from the filesystem.
in node this is done with
process.dlopen