Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

pkg not properly packing the built .node into executable, how to compile into executable? #749

Closed
ctlkkc opened this issue Aug 8, 2019 · 1 comment

Comments

@ctlkkc
Copy link

ctlkkc commented Aug 8, 2019

I am using the following module installed in the project

126 var msgpack = require('msgpack');

When pkg with the following config in the package.json:

 37   "bin": "server.js",
 38   "pkg": {
 39     "assets": [
 40       "*html",
 41       "libs/*",
 42       "utils/*",
 43       "docs/*",
 44       "images/*",
 45       "node_modules/**/*"
 46     ]
 47   },

There will be the following warning:

> Warning Cannot include addon %1 into executable.
  The addon must be distributed with executable as %2.
  /home/kcharl/tmp/pack-test/package/node_modules/msgpack/build/Release/msgpackBinding.node
  path-to-executable/msgpackBinding.node
> Warning Cannot include addon %1 into executable.
  The addon must be distributed with executable as %2.
  /home/kcharl/tmp/pack-test/package/node_modules/msgpack/build/Release/obj.target/msgpackBinding.node
  path-to-executable/msgpackBinding.node

I understood that putting the .node into path-to-executable/msgpackBinding.node will work around the problem, but without doing that, the following error will crash the pkg-ed executable:

kg/prelude/bootstrap.js:1185
      throw error;
      ^

Error: Cannot find module '/snapshot/package/node_modules/msgpack/lib/../build/Release/msgpackBinding'
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 Function.Module._resolveFilename (module.js:546:15)
    at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1287:46)
    at Function.Module._load (module.js:473:25)
    at Module.require (module.js:595:17)
    at Module.require (pkg/prelude/bootstrap.js:1166:31)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/snapshot/package/node_modules/msgpack/lib/msgpack.js:6:14)
    at Module._compile (pkg/prelude/bootstrap.js:1261:22)
    at Object.Module._extensions..js (module.js:662:10)
    at Module.load (module.js:564:32)

"1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. "

What does "specify a literal in 'require' call." mean? Does anyone know how to "specify a literal in 'require' call" in order to pkg the .node into the executable?
Thanks

@leerob
Copy link
Member

leerob commented Mar 2, 2021

Initial support has been merged with #837.

If there's anything else missing, please feel free to contribute back and I will take a look at the PR. Thank you! 🙏

@leerob leerob closed this as completed Mar 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants