warning question:
[email protected]
Warning Cannot include addon %1 into executable.
The addon must be distributed with executable as %2.
G:\gitbook\pkg-test\node_modules\node-sass\vendorwin32-x64-57\binding.node
path-to-executab
Environmen : win10
code:
var sass = require('node-sass');
var data = '#hello {\n color: #08c; }\n';
const result = sass.renderSync({ data: data }).css.toString();
if (result === data) {
console.log('ok');
}
I only copy node-sass test,but in my pc ,i cannot pkg node-sass; At the same time, I copy binding.node to root , but the same warning .
I have the same issue
Hi,
I have a similar problem with Sharp, also on Windows 10.
I have created a small example with this issue
package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"author": "",
"license": "ISC",
"dependencies": {
"sharp": "^0.18.3"
}
}
index.js
var sharp = require('sharp');
sharp('test.jpg')
.resize(200)
.toFile(new Date().getTime() + '.jpg')
.then((info) => { console.log(info) })
.catch((err) => { console.error(err) });
After running pkg the output is:
pkg -o .\exe\test.exe -c .\package.json .\index.js
[email protected]
Targets not specified. Assuming:
node8-win-x64
Warning Cannot include file %1 into executable.
The file must be distributed with executable as %2.
C:\Node-js\TSWorkspace\sandbox\test\node_modules\sharp\build\Release
path-to-executable/sharp/build/Release
Warning Cannot include file %1 into executable.
The file must be distributed with executable as %2.
C:\Node-js\TSWorkspace\sandbox\test\node_modules\sharp\vendor\lib
path-to-executable/sharp/vendor/lib
Any help would be appreciated!
I'm also experiencing this with sharp for a folder that doesn't seem to exist, so I'm not sure what, if anything, needs to be copied to root. Executable seems to work fine on my machine though 🤷♂️
node_modules/sharp/ has no vendor or vendor/lib subdirectories.
@hnlinzhi19 I ran into this issue today and have resolved it:
binding.node file into a mirror of the file structure in built directory. For example in my case I was packaging a file /git/vanilla-cli/src/buildtool.js into -/git/vanilla-cli/bin/buildtool-macos
The macOS version of the node binding was in /git/vanilla-cli/src/node_modules/node-sass/vendor/darwin-x64-57/binding.node. I needed to copy this binding to the location /git/vanilla-cli/bin/node-sass/vendor/darwin-x64-57/binding.node, and now it works.
This will only work on this particular OS that I'm running though. I intend to also build this to run on Windows and that will require packaging my tool on a windows machine and copying a second binding.node to a slightly different folder.
@patrickhulce There should be a file C:\Node-js\TSWorkspace\sandbox\test\node_modules\sharp\build\Release\sharp.node and ~30 files in C:\Node-js\TSWorkspace\sandbox\test\node_modules\sharp\vendor\lib.
You will need to copy the sharp.node to C:\Node-js\TSWorkspace\sandbox\test\exe\sharp\build\Release\sharp.node. You will probably also need to copy the ~30 .dylib files to C:\Node-js\TSWorkspace\sandbox\test\exe\sharp\vendor\lib.
I can't see your whole project structure but I would imagine it needs to look like this:
C:\Node-js\TSWorkspace\sandbox\test
|-- node_modules
|-- index.js
|-- exe
|---|-- test.exe
|---|-- sharp
|---|---|-- build\Release
|---|---|---|-- sharp.node
|---|---|-- vendor\lib
|---|---|---|-- A bunch of .dylib files
I'm not 100% sure about the .dylibs and how they differ from the .node files, but I can definitely see them in my node_modules folder.
The error messages for this type of thing should be much clearer.
@Charrondev Thx for info. I will copy these files manually. Shame that, PKG doesn't integrate those files to the exe file or copies them in a right directory.
UPDATE: I wiped node_modules, reinstalled, and the folder appeared. Not sure why it worked without it before, so I'm skeptical it's necessary, but it works now :man_shrugging: 👍
~Thanks for the response @Charrondev, but the problem is specifically that there is no vendor subdirectory in the node_modules/sharp folder. build/Release is there, I've copied it, and all seems well, but the vendor directory pkg tells me to copy simply doesn't exist.~
$ pkg
> Warning Cannot include directory %1 into executable.
The directory must be distributed with executable as %2.
node_modules/sharp/vendor/lib
path-to-executable/sharp/vendor/lib
$ ls node_modules/sharp/vendor/lib
ls: node_modules/sharp/vendor/lib: No such file or directory
$ ls -1 node_modules/sharp
CONTRIBUTING.md
LICENSE
README.md
binding.gyp
binding.js
build
docs
lib
node_modules
package.json
src
i had the same problem too @igorklopov
C addons cannot be included no matter if you put them in pkg.assets on package.json , any update on this?
I have the same issue
I also have this problem when I'm trying to build the small application with the node-pty module inside.
Would be great to have an ability just to mark files which will be just copied inside of binary keeping original path.
Any thoughts on it?
Build package with sqlite3. Same issue....
pack with oniguruma,Same issue.
still get a xx.exe thought.
I create a folder to put the file was warning, under the same folder with xx.exe. Then the exe works well.
This tool is really good~~~
It will be better if this issue is fixed.
You can use nexe package for now. It does the same work.
@vermadev95 nexe seems to have the same problem as this module when trying to include *.node files as resources. Hopefully, this gets fixed on both projects.
Is this issue has any process? I have same problem with use node-canvas.
Same issue on my end when packaging my app with bcrypt:

node_modules were added as asset using
"pkg": {
"assets": [
"node_modules/**/*",
]
}
I'll wait if a fix is in progress on this.
Same issue on my end when packaging my app with
bcrypt:
node_modules were added as asset using
"pkg": { "assets": [ "node_modules/**/*", ] }I'll wait if a fix is in progress on this.
yes,I encountered the same problem as you while using bcrypt, how did you solve it?
thank you.
This is my solution:
const BEFORE = 'before';
const AFTER = 'after';
handleModuleSharp(BEFORE, cwd);
await runCmd(cwd, 'pkg . --targets node12-linux-x64');
handleModuleSharp(AFTER, cwd);
function handleModuleSharp(arg: string, cwd: string) {
const pkgName = path.join(cwd, 'package.json');
const pkgInfo = fse.readJSONSync(pkgName);
if (!pkgInfo.dependencies.sharp) return;
const moduleSharpDir = path.join(cwd, 'node_modules/sharp');
const keyStr = {
raw: "require('../build/Release/sharp.node')",
replaced: "require(require('path').join(process.cwd(), 'sharp/build/Release/sharp.node'))",
};
const targetDir = path.join(moduleSharpDir, 'lib');
fse.readdirSync(targetDir).forEach(filename => {
if (!filename.endsWith('.js')) return;
const filepath = path.join(targetDir, filename);
let content = fse.readFileSync(filepath, {encoding: 'utf8'});
if (arg === BEFORE) content = content.replace(keyStr.raw, keyStr.replaced);
else if (arg === AFTER) content = content.replace(keyStr.replaced, keyStr.raw);
fse.writeFileSync(filepath, content);
});
if (arg === AFTER) {
fse.copySync(path.join(moduleSharpDir, 'build'), path.join(cwd, 'sharp/build'), {recursive: true});
fse.copySync(path.join(moduleSharpDir, 'vendor'), path.join(cwd, 'sharp/vendor'), {recursive: true});
};
};
So is there a proper solution? This problem has been bothering me for a long time, and I have been unable to package the Node. js file
Warning Cannot include directory %1 into executable.
The directory must be distributed with executable as %2.
%1: node_modules\puppeteer.local-chromium
%2: path-to-executable/puppetee
Hope to get help
and my index.js was this:
const puppeteer = require('puppeteer');
var fs = require("fs");
puppeteer.launch({headless:false}).then(async browser => {
const page = await browser.newPage();
await page.goto('https:www.baidu.com');
let html = await page.content()
// other actions...
// fs.writeFileSync(path.join(__dirname, 'm.txt'), html.toString(),'utf-8')
});
Most helpful comment
@patrickhulce There should be a file
C:\Node-js\TSWorkspace\sandbox\test\node_modules\sharp\build\Release\sharp.nodeand ~30 files inC:\Node-js\TSWorkspace\sandbox\test\node_modules\sharp\vendor\lib.You will need to copy the
sharp.nodetoC:\Node-js\TSWorkspace\sandbox\test\exe\sharp\build\Release\sharp.node. You will probably also need to copy the ~30 .dylib files toC:\Node-js\TSWorkspace\sandbox\test\exe\sharp\vendor\lib.I can't see your whole project structure but I would imagine it needs to look like this:
C:\Node-js\TSWorkspace\sandbox\test|--
node_modules|--
index.js|--
exe|---|--
test.exe|---|--
sharp|---|---|--
build\Release|---|---|---|--
sharp.node|---|---|--
vendor\lib|---|---|---|-- A bunch of
.dylib filesI'm not 100% sure about the
.dylibsand how they differ from the.nodefiles, but I can definitely see them in mynode_modulesfolder.The error messages for this type of thing should be much clearer.