vercel / pkg

Package your Node.js project into an executable

Home Page:https://npmjs.com/pkg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fs.promises readdir, readFile, etc. fail with ENOENT

plasne opened this issue · comments

fs.promises is still "Experimental" so there may be some bug with that, but readdir, readFile, etc. don't seem to work with assets, they all fail with ENOENT.

Just an FYI in case it saves someone else some time.

I have the same problem about fs #521
I also posted a log, but I still don't know how to fix that

Fixed in #521 for readFileSync

This issue is still there in pkg 4.2.2 when making a build with node 12. In node 12 fspromises is no longer experimental, so I would expect it to work.
I made a small project to test the support:
`
const fs = require('fs');
const fsPromises = fs.promises;
const path = require('path');
const file = path.resolve(path.join(__dirname, 'testfile.json'));

console.log(exists sync: ${fs.existsSync(file)});

fs.readFile(file, (err, data) => {
if (err) {
console.error(Failed to read ${file} using fs.readFile: ${err});
} else {
console.info(read file ${file} successfully using fs.readFile);
}
});
fsPromises.readFile(file).then(() => {
console.info(read file ${file} successfully using fsPromises.readFile);
}).catch(err=> {
console.error(Failed to read ${file} using fsPromises.readFile: ${err});
}
);
Output:
exists sync: true
read file D:\snapshot\pkg fspromise bug\testfile.json successfully using fs.readFile
Failed to read D:\snapshot\pkg fspromise bug\testfile.json using fsPromises.readFile: Error: ENOENT: no such file or directory, open 'D:\snapshot\pkg fspromise bug\testfile.json'
`

pkg fspromise bug.zip

this is still not working in pkg@4.4.3

Will work on this next.

Yes nextjs is almost unusable with pkg after this commit
vercel/next.js@2e1044f
part of this PR
You cannot read static pages through pkg at all. Only server side rendered ones

I'm still running into this. Is there any progress here?

I patched this on my fork at https://github.com/leafac/pkg

It’s available at npm install @leafac/pkg.

If the maintainers are interested in a pull request, I’d be happy to send it.

Merged!