Pkg: Error: File or directory. Please recompile adding it as asset or script.

Created on 4 May 2017  路  14Comments  路  Source: vercel/pkg

A quick support - I am doing a test compile. Here is my package .json script I have added.

"pkg": {
    "scripts": "build/**/*.js",
    "assets": "views/**/*"
  }

Here is the folder structure

folderstr

When I create a .exe it does create a exe but it gives an error saying this:

Error: File or directory 'C:\SGems\fullstack\5\views\index.html' was not included into executable at compilation stage. Please recompile adding it as asset or script.
at error_ENOENT (evalmachine.:0:0)
at findNativeAddonForStat (evalmachine.:0:0)
at statFromSnapshot (evalmachine.:0:0)
at Object.fs.stat (evalmachine.:0:0)
at SendStream.sendFile (C:\snapshot\SGems\fullstack\5node_modules\send\index.js:729:6)
at SendStream.pipe (C:\snapshot\SGems\fullstack\5node_modules\send\index.js:603:8)
at sendfile (C:\snapshot\SGems\fullstack\5node_modules\express\lib\response.js:1057:8)
at ServerResponse.sendFile (C:\snapshot\SGems\fullstack\5node_modules\express\lib\response.js:418:3)
at evalmachine.:0:0
at Layer.handle [as handle_request] (C:\snapshot\SGems\fullstack\5node_modules\express\lib\router\layer.js:95:5)

Also, is there a way to keep the server running in quiet mode? Any options?

question

Most helpful comment

I have same problem and solve it

"bin":"./index.js",
  "pkg": {
    "assets": "./node_modules/figlet/fonts/Standard.flf"
  }

and after that run:

pkg package.json

finally create another .exe file with directory name

All 14 comments

Please post your code.

Here is the code. Simple express server:

var express = require('express');
var app = express();
var server = require('http').Server(app);
//var io = require('socket.io')(server);

server.listen(8888);

app.use('/lib', express.static('lib'));
app.use(function (req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8888');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
    res.setHeader('Access-Control-Allow-Credentials', false);
    next();
});
app.get('/', function (req, res) {
  res.sendFile(__dirname + '/views/index.html');
});


If I include socket.io it gives an error related to declaration of this.wsEngine and require(this.wsEngine) in the index.js does not resolve the issue. Is there an example of how I can include this?

I tried but failed to reproduce. Can you make a repo?

app.zip

Please find files attached. Its a simple starter.

Seems the problem is that you run pkg app.js. Currently pkg does not know about package.json, because you specify app.js directly.

Instead you should add app.js as bin entry in package.json. And then run pkg package.json or simply pkg .

I added your code as an example for pkg. Thanks!
Please look at https://github.com/zeit/pkg/blob/master/examples/express/index.js#L9
You should use __dirname explicitly for serve-static root.

@igorklopov socket.io it gives an error related to declaration of this.wsEngine. How would I resolve that by explicit declarations? Any code examples?

@igorklopov any help is welcome :-)

i am also facing the same issue.. any solution ?

So what should i do?

What i have tried,

i just cloned the repo,,

cd examples/express
npm install
node index.js //works great
pkg . 
./index-macos // does not work says views was not included in compilation stage
pkg package.json
./index-macos //  does not work..  again same issue
pkg index.js
./index-macos //  does not work..  again same issue

Please note, i have not changed a single character in the example.

last line of this comment says "You should use __dirname explicitly for serve-static root."

at line 9 its written :
"__dirname is used here along with package.json.pkg.assets"

now next one is more confusing..
as in the documentation last line of section says that "This way you may even avoid creating pkg config for your project."

So even when the assets is included, nothing works..

May i am doing some silly mistake, please help me out.

T grotto

it was a silly mistake.. Just forget it.. it got it working..

Could you please tell me the reason / solution for your mistake?

@uullrich in the package.json i had not mentioned the "bin" property

I have same problem and solve it

"bin":"./index.js",
  "pkg": {
    "assets": "./node_modules/figlet/fonts/Standard.flf"
  }

and after that run:

pkg package.json

finally create another .exe file with directory name

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ksmithut picture ksmithut  路  4Comments

j-brown picture j-brown  路  4Comments

Nisthar picture Nisthar  路  4Comments

Nilesh0101 picture Nilesh0101  路  4Comments

peterjwest picture peterjwest  路  3Comments