Compatibility with npm pkg
bruceceng opened this issue · comments
WARNING: PLEASE READ THE DOC FOR DEBUGGING YOURSELF.
Describe the bug
Not exactly a bug, but a nice to have.
When attempting to use the fairly popular npm pkg tool to pack a project into an exe, the node-expose-sspi.node binary is not included in the package.
The reason is likely that you have in api.js
const filename =
./arch/${process.arch}/node-expose-sspi.node; module.exports = require(filename);
had you put it in one line like
module.exports = require( ./arch/${process.arch}/node-expose-sspi.node
);`
I think that the pkg parser would have picked it up and included it.
However, it may also be useful to approach it like npm systray which allows a different directory for the binary to be specified.
To Reproduce
Please provide the minimum of code to reproduce the issue.
You can provide the code directly in the issue, or through a github project that you make for proving the defect.
Indicate the step to reproduce if necessary, like:
- npm install pkg -g
- pkg [something using expose sspi].js
- [something using expose sspi].exe
- See error
Trace
pkg/prelude/bootstrap.js:1244
throw error;
^
Error: Cannot find module './arch/x64/node-expose-sspi.node'
Require stack:
- C:\snapshot\sspi-authenticate\node_modules\node-expose-sspi\lib\api.js
- C:\snapshot\sspi-authenticate\node_modules\node-expose-sspi\dist\index.js
- C:\snapshot\sspi-authenticate\SSPI-authentication-server.js
- 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 pr
ocess.cwd() or process.execPath.
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:964:15)
at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1346:46)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Module.require (internal/modules/cjs/loader.js:1024:19)
at Module.require (pkg/prelude/bootstrap.js:1225:31)
at require (internal/modules/cjs/helpers.js:72:18)
at Object. (C:\snapshot\sspi-authenticate\node_modules\node-expos
e-sspi\lib\api.js:2:18)
at Module._compile (pkg/prelude/bootstrap.js:1320:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:10)
at Module.load (internal/modules/cjs/loader.js:984:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\snapshot\sspi-authenticate\node_modules\node-expose-sspi\lib\api.j
s',
'C:\snapshot\sspi-authenticate\node_modules\node-expose-sspi\dist\inde
x.js',
'C:\snapshot\sspi-authenticate\SSPI-authentication-server.js'
],
pkg: true
}
Expected behavior
No errors when running packaged executable.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
See warning text about using a string literal for require.
Hi @bruceceng,
There is already an example with pkg where I have specified to manually move the node-expose-sspi.node
in the same directory as the node-expose-sspi.node
.
https://github.com/jlguenego/node-expose-sspi/tree/master/examples/express-pkg
I understand this copy instruction is a manual step that would be great to avoid if possible. I am going to make a deeper investigation to see if we can find a way to avoid it. I look at what you propose.
Unfortunately there is no solution :
The pkg documentation says:
"Native addons (.node files) use is supported, but packaging .node files inside the executable is not resolved yet. You have to deploy native addons used by your project to the same directory as the executable."
I prefer to keep consistent with the pkg documentation.
Please close this issue except if you see a solution. In this case please fork and submit a pull request.
Thanks.