Trying to copy a file from the snapshot filesystem to the real filesystem results in the following error:
ENOENT: no such file or directory. Seems to happen in all versions after 4.2.4.
Example code that should work:
fs.copyFile(
path.resolve(__dirname, 'some_file.json'),
path.resolve(process.cwd(), 'some_new_file.json')
)
Using ncp as a temporary workaround since it doesn't rely on the fs.copyFile function.
Another option that works is to use:
const fileBuffer = fs.readFileSync(path.resolve(__dirname, 'some_file.json'))
fs.writeFileSync(self.dynLibraryPath, fileBuffer)
I can confirm your little trick worked out for me o/
Trying to copy a file from the snapshot filesystem to the real filesystem results in the following error:
ENOENT: no such file or directory. Seems to happen in all versions after 4.2.4.Example code that should work:
fs.copyFile( path.resolve(__dirname, 'some_file.json'), path.resolve(process.cwd(), 'some_new_file.json') )
Maybe pkg does not kidnap function fs.copyFile. I meet the same issue, and I resolve it by replace copyFile with readFile & writeFile:
// previously:
function copyFile(sourcePath, targetPath) {
generatedFilePaths.push(targetPath);
fs.copyFileSync(sourcePath, targetPath);
}
// now:
function copyFile(sourcePath, targetPath) {
generatedFilePaths.push(targetPath);
const sourceData = fs.readFileSync(sourcePath, ENCODING);
fs.writeFileSync(targetPath, sourceData, ENCODING);
}
You need to not use the copy method from the fs-extra package. It must do something with path that pkg intercepts/changes.
It seems to be a regression bug, since it worked fine until 4.2.6.
This issue is still not solved. Any progress on this issue? @igorklopov
Hi, @igorklopov thanks for your great work. However, this issue is indeed a pain in our application and still not fixed for two years. Do you have any plans to get this issue to be solved, or suggest some work rounds. Many thanks and wish you a good day.
We workaround this issue by loading following patch at begin of main module: https://github.com/serverless/serverless/blob/94ff3b22ab13afc60fb4e672520b4db527ee0432/lib/utils/standalone-patch.js
Another option that works is to use:
const fileBuffer = fs.readFileSync(path.resolve(__dirname, 'some_file.json')) fs.writeFileSync(self.dynLibraryPath, fileBuffer)
this work with pkg 4.4.9
with node14
Most helpful comment
Another option that works is to use: