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

Created on 27 Jun 2018  路  7Comments  路  Source: vercel/pkg

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.

Most helpful comment

Will work on this next.

All 7 comments

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 [email protected]

Will work on this next.

Yes nextjs is almost unusable with pkg after this commit
https://github.com/vercel/next.js/pull/12026/commits/2e1044f85d1413baf8e0d0e14944632f47125335
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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

erikd picture erikd  路  3Comments

hellower picture hellower  路  3Comments

gillez picture gillez  路  4Comments

Nilesh0101 picture Nilesh0101  路  4Comments

Araknos picture Araknos  路  4Comments