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

[ERROR] Cannot include directory %1 into executable... Packaged correctly but no output, app not working #377

Closed
anthonyjdella opened this issue Mar 17, 2018 · 3 comments
Labels

Comments

@anthonyjdella
Copy link

anthonyjdella commented Mar 17, 2018

Hi, I created a small script in Node.js that uses a File System API to output data to a txt file and Chrome Headless Browser.
My goal was to package that app into an exe using pkg.

I ran:
npm install -g pkg
pkg myAppName.js

It has correctly given me myAppName-win.exe, however, when I run that executable, there is NO output to a txt file (which my app is supposed to do).

ERROR:
When running pkg myAppName.js, I get this warning:
Cannot include directory %1 into executable.
The directory must be distributed with executable as %2.

Can someone help? Thanks!

@anthonyjdella anthonyjdella changed the title Packaged correctly but no output, app not working [ERROR] Cannot include directory %1 into executable... Packaged correctly but no output, app not working Mar 17, 2018
@nashy18
Copy link

nashy18 commented Apr 11, 2018

I am also facing same issue. I am using module-alias while require.
I am calling
require('module-alias/register');
first line into app.js

please look into the issue

@darrensapalo
Copy link

I don't think that this is related to module-alias and is instead related to the usage of native addons (native things in node that your application is using).

The recommendation from the readme 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.

So prior to releasing, copy your dependencies from the node_modules folder and add them to the same directory of your executable file. That's what the error message says.

Example error message

Darren@SAMMIE-PC ~/g/c/d/amazon-keywords-processor# /cygdrive/d/Users/Darren/release/amazon-keywords-processor.exe
pkg/prelude/bootstrap.js:1244
      throw error;
      ^

Error: Cannot find module 'D:\snapshot\amazon-keywords-processor\node_modules\sqlite3\lib\binding\node-v72-win32-x64\node_sqlite3.node'
Require stack:
- D:\snapshot\amazon-keywords-processor\node_modules\sqlite3\lib\sqlite3-binding.js
- D:\snapshot\amazon-keywords-processor\node_modules\sqlite3\lib\sqlite3.js
- D:\snapshot\amazon-keywords-processor\node_modules\sqlite\main.js
- D:\snapshot\amazon-keywords-processor\dist\keyword-processor.js
- D:\snapshot\amazon-keywords-processor\dist\program\optimize-bids.js
- D:\snapshot\amazon-keywords-processor\dist\program\map-processing-operation.js
- D:\snapshot\amazon-keywords-processor\dist\main.js
- D:\snapshot\amazon-keywords-processor\bin.js
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 (internal/modules/cjs/loader.js:980:15)
    at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1346:46)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at Module.require (pkg/prelude/bootstrap.js:1225:31)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (D:\snapshot\amazon-keywords-processor\node_modules\sqlite3\lib\sqlite3-binding.js:4:15)
    at Module._compile (pkg/prelude/bootstrap.js:1320:22)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\snapshot\\amazon-keywords-processor\\node_modules\\sqlite3\\lib\\sqlite3-binding.js',
    'D:\\snapshot\\amazon-keywords-processor\\node_modules\\sqlite3\\lib\\sqlite3.js',
    'D:\\snapshot\\amazon-keywords-processor\\node_modules\\sqlite\\main.js',
    'D:\\snapshot\\amazon-keywords-processor\\dist\\keyword-processor.js',
    'D:\\snapshot\\amazon-keywords-processor\\dist\\program\\optimize-bids.js',
    'D:\\snapshot\\amazon-keywords-processor\\dist\\program\\map-processing-operation.js',
    'D:\\snapshot\\amazon-keywords-processor\\dist\\main.js',
    'D:\\snapshot\\amazon-keywords-processor\\bin.js'
  ],
  pkg: true
}

In my above example, the missing dependency is described in the error message:

Error: Cannot find module 'D:\snapshot\amazon-keywords-processor\node_modules\sqlite3\lib\binding\node-v72-win32-x64\node_sqlite3.node'

So you simply need to have a build script that copies that dependency into the same directory where you build your executable:

cp node_modules/sqlite3/lib/binding/node-v72-win32-x64/node_sqlite3.node ./node_sqlite3.node

This will enable your executable to find the missing dependency.

@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants